Java Code Examples for org.apache.commons.lang3.time.DateFormatUtils#format()
The following examples show how to use
org.apache.commons.lang3.time.DateFormatUtils#format() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DateUtils.java From azeroth with Apache License 2.0 | 5 votes |
/** * 格式化日期为日期字符串<br> * generate by: vakin jiang at 2012-3-7 * * @param orig * @param patterns * @return */ public static String format(Date date, String... patterns) { if (date == null) { return ""; } String pattern = TIMESTAMP_PATTERN; if (patterns != null && patterns.length > 0 && StringUtils.isNotBlank(patterns[0])) { pattern = patterns[0]; } return DateFormatUtils.format(date, pattern); }
Example 2
Source File: DateUtils.java From jeesuite-libs with Apache License 2.0 | 5 votes |
/** * 格式化日期字符串<br> * generate by: vakin jiang at 2012-3-7 * * @param dateStr * @param patterns * @return */ public static String formatDateStr(String dateStr, String... patterns) { String pattern = TIMESTAMP_PATTERN; if (patterns != null && patterns.length > 0 && StringUtils.isNotBlank(patterns[0])) { pattern = patterns[0]; } return DateFormatUtils.format(parseDate(dateStr), pattern); }
Example 3
Source File: DateUtils.java From jeesuite-libs with Apache License 2.0 | 5 votes |
/** * 格式化日期为日期字符串<br> * generate by: vakin jiang at 2012-3-7 * * @param orig * @param patterns * @return */ public static String format(Date date, String... patterns) { if (date == null) return ""; String pattern = TIMESTAMP_PATTERN; if (patterns != null && patterns.length > 0 && StringUtils.isNotBlank(patterns[0])) { pattern = patterns[0]; } return DateFormatUtils.format(date, pattern); }
Example 4
Source File: FontImage.java From kbase-doc with Apache License 2.0 | 5 votes |
/** * 根据指定的文本创建图片 * @author eko.zhan at 2018年9月18日 上午10:14:44 * @param text * @throws WatermarkException */ public static File createImage(String text) throws WatermarkException { Font font = new Font("宋体", Font.PLAIN, 100); int[] arr = getWidthAndHeight(text, font); int width = arr[0]; int height = arr[1]; // 创建图片 BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR);//创建图片画布 // Graphics gs = image.getGraphics(); // Graphics2D g = (Graphics2D)gs; // g.setColor(Color.WHITE); // 先用白色填充整张图片,也就是背景 Graphics2D g = image.createGraphics(); // 增加下面代码使得背景透明 image = g.getDeviceConfiguration().createCompatibleImage(width, height, Transparency.TRANSLUCENT); g.dispose(); g = image.createGraphics(); // 背景透明代码结束 // g.fillRect(0, 0, width, height);//画出矩形区域,以便于在矩形区域内写入文字 g.setColor(new Color(242, 242, 242));// 再换成黑色,以便于写入文字 g.setFont(font);// 设置画笔字体 g.translate(10, 10); // g.rotate(0.1*Math.PI);//旋转 g.rotate(0.16); g.drawString(text, 0, font.getSize());// 画出一行字符串 g.dispose(); String property = System.getProperty("java.io.tmpdir"); File imageFile = new File(property + "/kbs-watermark-" + DateFormatUtils.format(new Date(), "yyyyMMddHHmmss") + ".png"); try { // 输出png图片 ImageIO.write(image, "png", imageFile); } catch (IOException e) { throw new WatermarkException("IOException", e); } return imageFile; }
Example 5
Source File: DateTimeUtil.java From sophia_scaffolding with Apache License 2.0 | 5 votes |
/** * 资源表示方式的时间差函数 * * @param startDate * 指定时间 * @param endDate * 结束时间 * @return 时间差指定格式字符串 */ public static String resDiff(Date startDate, Date endDate) { Object[] obj = timeDifference(startDate, endDate); String value = ""; if (Long.parseLong(obj[3].toString()) > 7) { value = DateFormatUtils.format(startDate, "yyyy-MM-dd HH:mm"); } else { value = otherDiff(startDate, endDate); } return value; }
Example 6
Source File: ImageRenameHandler.java From markdown-image-kit with MIT License | 5 votes |
/** * 根据配置重新设置 imageName * * @param data the data * @param imageIterator the image iterator * @param markdownImage the markdown image * @return the boolean */ @Override public void invoke(EventData data, Iterator<MarkdownImage> imageIterator, MarkdownImage markdownImage) { String imageName = markdownImage.getImageName(); MikState state = MikPersistenComponent.getInstance().getState(); // 处理文件名有空格导致上传 gif 变为静态图的问题 imageName = imageName.replaceAll("\\s*", ""); int sufixIndex = state.getSuffixIndex(); Optional<SuffixEnum> sufix = EnumsUtils.getEnumObject(SuffixEnum.class, e -> e.getIndex() == sufixIndex); SuffixEnum suffixEnum = sufix.orElse(SuffixEnum.FILE_NAME); switch (suffixEnum) { case FILE_NAME: break; case DATE_FILE_NAME: // 删除原来的时间前缀 imageName = imageName.replace(DateFormatUtils.format(new Date(), "yyyy-MM-dd-"), ""); imageName = DateFormatUtils.format(new Date(), "yyyy-MM-dd-") + imageName; break; case RANDOM: if(!imageName.startsWith(PREFIX)){ imageName = PREFIX + CharacterUtils.getRandomString(6) + ImageUtils.getFileExtension(imageName); } break; default: break; } markdownImage.setImageName(imageName); }
Example 7
Source File: StringUtil.java From xmfcn-spring-cloud with Apache License 2.0 | 5 votes |
/** * 创建一个随机数. * * @return 随机六位数+当前时间yyyyMMddHHmmss */ public static String randomCodeUtil() { String cteateTime = DateFormatUtils.format(new Date(), "yyyyMMddHHmmss"); int num = RandomUtils.nextInt(100000, 1000000); String result = cteateTime + StringUtils.leftPad(num + "", 6, "0"); return result; }
Example 8
Source File: IndexServiceImpl.java From Qualitis with Apache License 2.0 | 5 votes |
@Override public IndexApplicationTodayResponse getTodaySubmitApplications(String username, PageRequest pageRequest) { // Find applications submitted today String today = DateFormatUtils.format(new Date(), DATE_FORMAT_PATTERN); List<Application> applications = getUserApplications(username, today, pageRequest); if (applications == null || applications.isEmpty()) { LOGGER.info("[Home overview]user:{},date:{},The user and the task submitted by the specified date were not found.", username, today); return null; } // Get total num of applications today long totalNum = countUserApplications(username, today); // Get successful total num of applications today long totalSuccNum = countUserSuccApplications(username, today); // Get failed total num of applications today long totalFailNum = countUserFailApplications(username, today); // Get not pass total num of applications today long totalFailCheckNum = countUserFailCheckApplications(username, today); LOGGER.info("[Home overview]user:{},date:{},Find {} tasks submitted by the user's specified date, for a total of {}.", username, today, applications.size(), totalNum); List<IndexApplicationResponse> applicationResponses = new ArrayList<>(); for (Application application : applications) { List<Task> tasks = taskDao.findByApplication(application); IndexApplicationResponse applicationResponse = new IndexApplicationResponse(application, tasks); applicationResponses.add(applicationResponse); } return new IndexApplicationTodayResponse(applicationResponses, totalNum, totalSuccNum, totalFailNum, totalFailCheckNum); }
Example 9
Source File: MybatisInterceptor.java From DDMQ with Apache License 2.0 | 5 votes |
private String getParameterValue(Object obj) { String value; if (obj instanceof String) { value = "'" + obj.toString() + "'"; } else if (obj instanceof Date) { value = "'" + DateFormatUtils.format((Date) obj, DATE_FORMAT) + "'"; } else { if (obj != null) { value = obj.toString(); } else { value = ""; } } return Matcher.quoteReplacement(value); }
Example 10
Source File: DefaultEventcheckReceiver.java From DataSphereStudio with Apache License 2.0 | 5 votes |
private void initReceiverTimes(){ todayStartTime = DateFormatUtils.format(new Date(), "yyyy-MM-dd 00:00:00"); todayEndTime = DateFormatUtils.format(new Date(), "yyyy-MM-dd 23:59:59"); allStartTime = DateFormatUtils.format(new Date(), "10000-01-01 00:00:00"); allEndTime = DateFormatUtils.format(new Date(), "9999-12-31 23:59:59"); nowStartTime = DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"); }
Example 11
Source File: DateTimeUtil.java From sophia_scaffolding with Apache License 2.0 | 5 votes |
/** * 动态表示方式的时间差函数 * * @param startDate * 指定时间 * @param endDate * 结束时间 * @return 时间差指定格式字符串 */ public static String dynDiff(Date startDate, Date endDate) { String startDay = DateFormatUtils.format(startDate, "dd"); String endtDay = DateFormatUtils.format(endDate, "dd"); String value = ""; if (startDay.equals(endtDay)) { value = DateFormatUtils.format(startDate, " HH:mm"); } else { value = otherDiff(startDate, endDate); } return value; }
Example 12
Source File: DateTools.java From o2oa with GNU Affero General Public License v3.0 | 4 votes |
public static String formatDate(Date date) { return DateFormatUtils.format(date, format_yyyyMMdd); }
Example 13
Source File: DateTools.java From o2oa with GNU Affero General Public License v3.0 | 4 votes |
public static String compactDate(Date date) { return DateFormatUtils.format(date, formatCompact_yyyyMMdd); }
Example 14
Source File: DateUtil.java From ehousechina with Apache License 2.0 | 4 votes |
/** * 得到当前日期字符�? 格式(yyyy-MM-dd�? pattern可以为:"yyyy-MM-dd" "HH:mm:ss" "E" */ public static String getDate(String pattern) { return DateFormatUtils.format(new Date(), pattern); }
Example 15
Source File: PerfRecord.java From DataLink with Apache License 2.0 | 4 votes |
public String getDatetime(){ if(startTime == null){ return "null time"; } return DateFormatUtils.format(startTime, datetimeFormat); }
Example 16
Source File: DateUtils.java From Shiro-Action with MIT License | 4 votes |
/** * 日期路径 即年/月/日 如20180808 */ public static String dateTime() { Date now = new Date(); return DateFormatUtils.format(now, "yyyyMMdd"); }
Example 17
Source File: DateTools.java From o2oa with GNU Affero General Public License v3.0 | 4 votes |
public static String now() { return DateFormatUtils.format(new Date(), format_yyyyMMddHHmmss); }
Example 18
Source File: DateUtils.java From cms with Apache License 2.0 | 4 votes |
/** * 得到当前日期字符串 格式(yyyy-MM-dd) pattern可以为:"yyyy-MM-dd" "HH:mm:ss" "E" */ public static String getDate(String pattern) { return DateFormatUtils.format(new Date(), pattern); }
Example 19
Source File: VelocityTool.java From leetcode-editor with Apache License 2.0 | 4 votes |
public static String date(String format) { return DateFormatUtils.format(new Date(), format); }
Example 20
Source File: MyDateUtils.java From spring-boot with Apache License 2.0 | 2 votes |
/** * 获取当前日期字符串 * * @param parsePatterns 日期格式 * @return 当前日期字符串 */ public static String getCurrentDateString(String parsePatterns) { return DateFormatUtils.format(new Date(), parsePatterns); }