得到过去的时间:
example one:
example two:
转换日期成String:
example one:
private Date getDateTime(){
Calendar calendar = Calendar.getInstance();
calendar.set(2011, Calendar.DECEMBER, 1, 23, 0, 0);
return calendar.getTime();
}example two:
String.valueOf(new Date().getTime() - 24 * 60 * 60 * 1000)转换日期成String:
private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public static String covertDate(Date d) {
String ret = "";
if (d != null) {
ret = sdf.format(d);
}
return ret;
}
本文提供了两个Java日期操作的例子,包括如何设置过去的特定日期并获取其时间戳,以及如何将日期对象转换为字符串格式。
1449

被折叠的 条评论
为什么被折叠?



