import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateTest {
public static void main(String[] args) {
Date d = new Date(94,5,1,4,0);
long l = d.getTime();
Date d2 = new Date();
long ll = d2.getTime();
System.out.println((ll-l)/1000/60/60/24);
// 日期格式化
String s1 = "yyyy-MM-dd HH:mm:ss";
String s2 = "yyyy年MM月dd日 HH时mm分ss秒";
String s3 = "yyyy/MM/dd HH:mm:ss";
String s4 = "yyyy-MM-dd";
String s5 = "yyyy.MM.dd HH:mm:ss";
Date date = new Date();// 当前时间
SimpleDateFormat sdf = new SimpleDateFormat(s5);
// Date -> String
String s = sdf.format(date);
System.out.println(s);
// String -> Date
String dd = "2017.10.01 12:53:05";
Date date1;
try {
date1 = sdf.parse(dd);
System.out.println(date1);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
网友评论