java 获取今天零点零分零秒的毫秒数、今天23点59分59秒的毫秒数

import java.sql.Timestamp;
import java.util.TimeZone;

/**
 * @Description:
 * @Author:chenyanbin
 * @Date:2021/4/8 下午3:24
 * @Versiion:1.0
 */
public class Demo02 {
    public static void main(String[] args) {
        long current=System.currentTimeMillis();//当前时间毫秒数
        long zero=current/(1000*3600*24)*(1000*3600*24)- TimeZone.getDefault().getRawOffset();//今天零点零分零秒的毫秒数
        long twelve=zero+24*60*60*1000-1;//今天23点59分59秒的毫秒数
        long yesterday=System.currentTimeMillis()-24*60*60*1000;//昨天的这一时间的毫秒数
        System.out.println(new Timestamp(current));//当前时间
        System.out.println(new Timestamp(yesterday));//昨天这一时间点
        System.out.println(new Timestamp(zero));//今天零点零分零秒
        System.out.println(new Timestamp(twelve));//今天23点59分59秒
    }
}

 

posted @ 2021-04-08 15:25  陈彦斌  阅读(739)  评论(0编辑  收藏  举报