1.年月日
public static void main(String[] args) {
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
int nowDay = Integer.parseInt(df.format(System.currentTimeMillis()).toString());
System.out.println(nowDay);//结果20181017
}
2.年月日时分秒
public static void main(String[] args) {
SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
Long nowDay = Long.parseLong(df.format(System.currentTimeMillis()).toString());
System.out.println(nowDay);//结果20181017150714
}
3.获取时间戳,精确到秒
public static int getTimestamp() {
int timestamp = 0;
timestamp = (int) (System.currentTimeMillis() / 1000);
return timestamp;
}
1579

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



