Date各种格式应用如下:
public class DateTest {
public static void main(String[] args) {
// java sal date
Date utilDate = new java.util.Date();
Date sqDdate1 = new java.sql.Timestamp(System.currentTimeMillis());
Date sqDdate2 = new java.sql.Date(System.currentTimeMillis());
Date sqDdate3 = new java.sql.Time(System.currentTimeMillis());
// 时间戳
long timeStamp = System.currentTimeMillis();
Date date = new Date();
// date format
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss 第ww周 第DDD天 ");
String formatDate = sdf.format(date);
// 几个小时前时间
LocalTime minusHours = LocalTime.now().minusHours(5);
LocalTime now = LocalTime.now();
LocalDateTime now2 = LocalDateTime.now();
// 时间最大值
Date endTime = new Date(Long.MAX_VALUE);
System.out.println("utilDate:" + utilDate);
System.out.println("sqDdate1:" + sqDdate1);
System.out.println("sqDdate2:" + sqDdate2);
System.out.println("sqDdate3:" + sqDdate3);
System.out.println("timeStamp:" + timeStamp);
System.out.println("date:" + date);
System.out.println("formatDate:" + formatDate);
System.out.println("minusHours:" + minusHours);
System.out.println("endTime:" + endTime);
System.out.println("now:" + now);
System.out.println("now2:" + now2);
}
}
输出结果为:
utilDate:Mon Feb 18 21:52:15 CST 2019
sqDdate1:2019-02-18 21:52:15.784
sqDdate2:2019-02-18
sqDdate3:21:52:15
timeStamp:1550497935784
date:Mon Feb 18 21:52:15 CST 2019
formatDate:2019年02月18日 21:52:15 第08周 第049天
minusHours:16:52:15.900
endTime:Sun Aug 17 15:12:55 CST 292278994
now:21:52:15.900
now2:2019-02-18T21:52:15.901