日期时间的使用

Posted lin3615

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了日期时间的使用相关的知识,希望对你有一定的参考价值。

Date用法

Date datetime = new Date();
//获取当前日期


String date = String.format("%tF", datetime);
System.out.println(date); // 2020-03-08

// 获取当前时间	
String time = String.format("%tT", datetime);
System.out.println(time); // 18:22:40

// 获取1970-01-01 00:00:00到当前的秒数
String second = String.format("%ts", datetime);
System.out.println(second); // 1583663377



// 获取从1970-01-01 00:00:00到当前的毫秒
String miSecond = String.format("%tQ",datetime);
System.out.println(miSecond); // 1583663518832

  

以上是关于日期时间的使用的主要内容,如果未能解决你的问题,请参考以下文章