1. 日期格式工具类:
package com.ant.jdk8.lang; import org.apache.commons.lang3.time.DateFormatUtils; import java.util.Date; /** * @author wangll * @date 2018/7/17 */ public class DateFormatDemo { public static void main(String[] args) { System.out.println(DateFormatUtils.format(new Date(),"yyyy-MM-dd HH:mm:ss")); } }
2. 日期工具类:
package com.ant.jdk8.lang; import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.commons.lang3.time.DateUtils; import java.util.Date; /** * @author wangll * @date 2018/7/17 */ public class DateDemo { public static void main(String[] args) { Date date = new Date(); System.out.println(DateFormatUtils.format(date,"yyyy-MM-dd HH:mm:ss")); Date newDate = DateUtils.addYears(date,1); System.out.println(DateFormatUtils.format(newDate,"yyyy-MM-dd HH:mm:ss")); } }
原文地址:https://www.cnblogs.com/i-hard-working/p/9326807.html
时间: 2024-10-16 23:38:17