Java8 / java.time API
Date and Time API new feature in Java8 ,
mainly these objects are immutable and thread safe , these API contains four packages ,
java.time.*;
java.time.chrono.*;
java.time.format.*;
java.time.temporal.*;
java.time.zone.*;
now we will see how to make use of these libraries in our programming usage .
here i’m taking a sample class that will print the current timezone date and time and custom time zone date and time .
package com.javamix.dateandtime;
import java.time.*;
public class CurrentAndCustomTimeZone {
public static void main(String[] args) {
try {
System.out.println(ZonedDateTime.now()); // it will print the current time and zone
// getting the time of particular zone
Clock clock = Clock.system(ZoneId.of("Asia/Aden"));
System.out.println("Asia/Aden" + LocalDateTime.now(clock));} catch (DateTimeException dex) {
dex.printStackTrace();
}}
}
