package theChildOfGod.bjxy.test;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class TestDateFormat {
public static void main(String[] args) {
DateFormat df1 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
Date d1 = new Date(113213546546L);
String str1 = df1.format(d1);//将时间对象按照格式化字符串,
//转化成字符串
System.out.println(str1);
System.out.println("###################");
String str2 = "1997-7-1";
DateFormat df2= new SimpleDateFormat("yyyy,MM,dd");
try {
Date d2 = df2.parse(str2);
System.out.println(d2);
}catch(ParseException e){
e.printStackTrace();
}
}
}
常用类----DateFormat和SimpleDateFormat_时间和字符串之间的转换
猜你喜欢
转载自blog.csdn.net/qq_39588027/article/details/79991618
今日推荐
周排行