1.当前日转String转时间戳
2.当前日期转时间戳
3.时间戳转String
timestamp to Date
[img]http://dl2.iteye.com/upload/attachment/0097/8482/525e7e1d-ebf9-3e1e-bd61-b45ce1632a36.jpg[/img]
比较
<code>
String DateStr1 = "2014-10-1 10:20:16";
String DateStr2 = "2014-10-07 15:50:35";
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date dateTime1 = dateFormat.parse(DateStr1);
Date dateTime2 = dateFormat.parse(DateStr2);
int i = dateTime1.compareTo(dateTime2);
System.out.println(i < 0);
</code>
Date dt=new Date();
SimpleDateFormat matter1=new SimpleDateFormat("yyyy-MM-dd");
System.out.println(matter1.format(dt));
DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Timestamp ts = new Timestamp(format.parse(matter1.format(dt)).getTime());
System.out.println(ts.toString());
2.当前日期转时间戳
java.util.Date today = new java.util.Date();
return new java.sql.Timestamp(today.getTime());
3.时间戳转String
public static String timestamp2Str(Timestamp tp) {
if (tp == null) {
return "";
}
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String str = df.format(tp);
return str;
}
timestamp to Date
[img]http://dl2.iteye.com/upload/attachment/0097/8482/525e7e1d-ebf9-3e1e-bd61-b45ce1632a36.jpg[/img]
比较
<code>
String DateStr1 = "2014-10-1 10:20:16";
String DateStr2 = "2014-10-07 15:50:35";
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date dateTime1 = dateFormat.parse(DateStr1);
Date dateTime2 = dateFormat.parse(DateStr2);
int i = dateTime1.compareTo(dateTime2);
System.out.println(i < 0);
</code>