Date date =new Date();/**默认当前日期时间格式*/
System.out.println(date);
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//日期格式化--年月日时分秒
System.out.println(sdf.format(date));/**将date日期转换成string类型*/
String date1="2021-10-26 00:00:00";
System.out.println(sdf.parse(date1));/**将string转化为默认时间格式*/
long nowDate = new Date().getTime();/**获取当前时间戳*/
日期之间进行比较不精确时分秒使用 日期.compareTo(比较日期)是int类型的 0是相等
本文介绍如何在Java中使用SimpleDateFormat进行日期格式转换,并探讨了日期比较的精确性,重点讲解了compareTo方法的应用。

2367

被折叠的 条评论
为什么被折叠?



