SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String 转成 Date String ti="2010-11-25 20:11:00";
Date 转成 String System.out.println(sdf.format(new Date()));
String 转成 Timestamp Timestamp ts = Timestamp.valueOf("2011-1-14 08:11:00");
Timestamp 转成 String sdf.format(ts);
Timestamp和Date多数用法是一样的。 Date 转 TimeStamp SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String time = df.format(new Date()); Timestamp ts = Timestamp.valueOf(time);
日期比较大小 String ti="2010-11-25 20:11:00"; String ti2="2011-11-26 20:11:00"; int c=ti2.compareTo(ti); System.out.println("一样大"); }else{
Date/ Timestamp 转成 Calendar Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.YEAR, 2); //日期加2年 |
java中String Date Timestamp Calendar 之间的关系及转换
最新推荐文章于 2021-12-10 11:18:50 发布