1.创建DateFormat对象
DateFormat df=new SimpleDateFormat("yyyy-MM-dd");//指定格式
Date date=new Date(1607616000000L);
String str_time=df.format(date);
System.out.println(str_time);
2.将date转换成String对象
Date date =new Date(1607616000000L);
DateFormat df=new SimpleDateFormat("yyyy年MM月dd日");
String str=df.format(date);//格式化
3.将String对象转换成Date
String str="2019年03月13日";
DateFormate df=new simpleFormat("yyyy年MM月dd日);
Date date=df.parse(str);
本文详细介绍了如何使用Java进行日期与字符串之间的相互转换,包括创建DateFormat对象、将Date转换为String及将String转换为Date的方法。
791

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



