1.当前日转String转时间戳
class="java" name="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
- 大小: 6.3 KB