ZonedDateTime

作者: Djbfifjd | 来源:发表于2019-07-05 13:19 被阅读5次
    import java.time.ZonedDateTime;
    import java.time.temporal.ChronoUnit;
    import java.util.Date;
    
    public class test {
    
        public static void main(String[] args) {
    
            final ZonedDateTime now = ZonedDateTime.now(); //当前时间
            System.out.println("now:" + now);
            final ZonedDateTime todayZero = now.truncatedTo(ChronoUnit.DAYS); //今天的0点
            System.out.println("todayZero:" + todayZero);
            final ZonedDateTime tomorrowZero = todayZero.plusDays(1); //明天的0点
            System.out.println("tomorrowZero:" + tomorrowZero);
            final ZonedDateTime firstDayOfMonth = todayZero.withDayOfMonth(1); //当月1号0点
            System.out.println("firstDayOfMonth:" + firstDayOfMonth);
            final ZonedDateTime nextDayOfMonth = firstDayOfMonth.plusMonths(1);//下月1号0点
            System.out.println("nextDayOfMonth:" + nextDayOfMonth);
            final Date date = Date.from(todayZero.toInstant()); //ZoneDateTime 转换成Date
            System.out.println("date:" + date);
        }
    }
    
    ZonedDateTime.jpg

    相关文章

      网友评论

        本文标题:ZonedDateTime

        本文链接:https://www.haomeiwen.com/subject/eknshctx.html