java 如何获取当前时间的时间戳

Python011

java 如何获取当前时间的时间戳,第1张

时间戳通常是”yyyyMMddHHmmss“的,举例:

Date date = new Date()

SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss")

String str = sdf.format(date)

输出结果:20150704173752。

备注:时间戳中的时间显示格式可以根据实际情况设置即可。

public Long getToday(){

DateTime now = new DateTime()

return new DateTime(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(), 0, 0, 0, 0).getMillis()

}

public Long getTomorrow(){

DateTime now = new DateTime()

return new DateTime(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(), 0, 0, 0, 0).plusDays(1).getMillis()

}