org.apache.commons.lang3.time.DateFormatUtils#format ( )源码实例Demo

下面列出了org.apache.commons.lang3.time.DateFormatUtils#format ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: xmfcn-spring-cloud   文件: StringUtil.java
/**
 * 创建一个随机数.
 *
 * @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;
}
 
源代码2 项目: sophia_scaffolding   文件: DateTimeUtil.java
/**
 * 动态表示方式的时间差函数
 *
 * @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;
}
 
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");
}
 
源代码4 项目: DDMQ   文件: MybatisInterceptor.java
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);
}
 
源代码5 项目: Qualitis   文件: IndexServiceImpl.java
@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);
}
 
源代码6 项目: azeroth   文件: DateUtils.java
/**
 * 格式化日期为日期字符串<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);
}
 
源代码7 项目: markdown-image-kit   文件: ImageRenameHandler.java
/**
 * 根据配置重新设置 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);
}
 
源代码8 项目: sophia_scaffolding   文件: DateTimeUtil.java
/**
 * 资源表示方式的时间差函数
 *
 * @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;
}
 
源代码9 项目: kbase-doc   文件: FontImage.java
/**
	 * 根据指定的文本创建图片
	 * @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;
	}
 
源代码10 项目: jeesuite-libs   文件: DateUtils.java
/**
 * 格式化日期为日期字符串<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);
}
 
源代码11 项目: jeesuite-libs   文件: DateUtils.java
/**
 * 格式化日期字符串<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);
}
 
源代码12 项目: leetcode-editor   文件: VelocityTool.java
public static String date(String format) {
    return DateFormatUtils.format(new Date(), format);
}
 
源代码13 项目: cms   文件: DateUtils.java
/**
 * 得到当前日期字符串 格式(yyyy-MM-dd) pattern可以为:"yyyy-MM-dd" "HH:mm:ss" "E"
 */
public static String getDate(String pattern) {
	return DateFormatUtils.format(new Date(), pattern);
}
 
源代码14 项目: Shiro-Action   文件: DateUtils.java
/**
 * 日期路径 即年/月/日 如20180808
 */
public static String dateTime() {
    Date now = new Date();
    return DateFormatUtils.format(now, "yyyyMMdd");
}
 
源代码15 项目: o2oa   文件: DateTools.java
public static String formatDate(Date date) {
	return DateFormatUtils.format(date, format_yyyyMMdd);
}
 
源代码16 项目: o2oa   文件: DateTools.java
public static String compactDate(Date date) {
	return DateFormatUtils.format(date, formatCompact_yyyyMMdd);
}
 
源代码17 项目: ehousechina   文件: DateUtil.java
/**
 * 得到当前日期字符�? 格式(yyyy-MM-dd�? pattern可以为:"yyyy-MM-dd" "HH:mm:ss" "E"
 */
public static String getDate(String pattern) {
	return DateFormatUtils.format(new Date(), pattern);
}
 
源代码18 项目: DataLink   文件: PerfRecord.java
public String getDatetime(){
    if(startTime == null){
        return "null time";
    }
    return DateFormatUtils.format(startTime, datetimeFormat);
}
 
源代码19 项目: o2oa   文件: DateTools.java
public static String now() {
	return DateFormatUtils.format(new Date(), format_yyyyMMddHHmmss);
}
 
源代码20 项目: spring-boot   文件: MyDateUtils.java
/**
 * 获取当前日期字符串
 *
 * @param parsePatterns 日期格式
 * @return 当前日期字符串
 */

public static String getCurrentDateString(String parsePatterns) {
    return DateFormatUtils.format(new Date(), parsePatterns);
}