public class NuDate {

    public static void main(String[] args) throws InterruptedException {
        Instant start = Instant.now();//Instant represents an Instant point on the timeline
        //System.out.println(start.getEpochSecond()); // Milliseconds since 1970
        //Thread.sleep(2000);
        Instant end = Instant.now();
        Duration duration = Duration.between(start, end);//Duration The model is a directed Duration, which means that the Duration can be negative.
		//System.out.println(duration.getSeconds());


		LocalDateTime without a time zone (not recommended)
		//ZoneID The model is a directed duration, which means the duration can be negative.
		//ofInstant(Instant Instant, ZoneId Zone) obtains ZonedDateTime instance from an Instant.
        ZonedDateTime dtUTC = ZonedDateTime.ofInstant(start, ZoneId.of("UTC"));

		//System.out.println(dtUTC);

        ZonedDateTime dtSH = start.atZone(ZoneId.systemDefault());//systemDefault()=of("Asia/Shanghai")
        //System.out.println(dtSH);

		// Get the set of available zone identifiers.
        //System.out.println(ZoneRulesProvider.getAvailableZoneIds());

		//ofPattern(String pattern) creates a formatter that uses the specified pattern.
		DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss xx");
		//format(TemporalAccessor temporal) Uses this formatter to format date and time objects.
		String dateStr = df.format(dtSH);

		//System.out.println(dateStr);

		// Parse (CharSequence text, DateTimeFormatter Formatter) obtains ZonedDateTime instances from text strings using a specific format
		// deserialize
		ZonedDateTime dtSH2 = ZonedDateTime.parse(dateStr, df);
		//System.out.println(dtSH2);


// ZonedDateTime nextTues = dtSH.with(TemporalAdjusters.next(DayOfWeek.TUESDAY));
// System.out.println(nextTues);}}Copy the code