`
qtlkw
  • 浏览: 301161 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

java 日期函数

阅读更多
得到过去的时间:
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;
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics