java日期转时间戳,时间戳转日期,时间戳提取前10位

简洁方法(时间戳/1000存储)

    @Test
    public void timestamp() throws Exception {
    
    
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        long firstdate = sf.parse("1991-01-01 00:00:00").getTime()/1000;
        long lastdate = sf.parse("1991-12-31 00:00:00").getTime()/1000;
        String d1 = sf.format(firstdate);
        String d2 = sf.format(lastdate);
        System.out.println(d1+" = "+firstdate);
        System.out.println(d2+" = "+lastdate);
    }

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_48860638/article/details/121495970