测试时间戳,相加,结算三天后的时间戳和一天后的时间戳

测试时间戳,相加,计算三天后的时间戳和一天后的时间戳

测试代码:
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
发布了8 篇原创文章 · 获赞 13 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_41593169/article/details/83303227