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
网友评论