欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

java判断两个时间是不是同一天的方法

程序员文章站 2024-02-25 10:16:04
复制代码 代码如下:public class timeutil {     public static final int seconds_...

复制代码 代码如下:

public class timeutil {

    public static final int seconds_in_day = 60 * 60 * 24;
    public static final long millis_in_day = 1000l * seconds_in_day;

    public static boolean issamedayofmillis(final long ms1, final long ms2) {
        final long interval = ms1 - ms2;
        return interval < millis_in_day
                && interval > -1l * millis_in_day
                && today(ms1) == today(ms2);
    }
    private static long today(long millis) {
        return (millis + timezone.getdefault().getoffset(millis)) / millis_in_day;
    }
}