package com.test;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Test1Time {
public static void main(String[] args){
int i=(int) (System.currentTimeMillis() / 1000);
System.out.println(i);
int a = 1;
int b = 3;
int j = i+a*60 * 60 * 24;
int z = i+b*60 * 60 * 24;
System.out.println("一天后的时间戳:"+j);
System.out.println("三天后的时间戳:"+z);
Date d = new Date();
System.out.println(d);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String dateNowStr = sdf.format(d)+" 00:00:00";
System.out.println("格式化后的日期:" + dateNowStr);
}
}
测试结果:
1540195837
一天后的时间戳:1540282237
三天后的时间戳:1540455037
Mon Oct 22 16:10:37 CST 2018
格式化后的日期:2018-10-22 00:00:00
Process finished with exit code 0