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();
}
}
}
Common classes----DateFormat and SimpleDateFormat_ conversion between time and string
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=324572348&siteId=291194637
Recommended
Ranking