Java8 時區DateTime API


時區日期時間的API正在使用當時區要被考慮時。

讓我們來看看他們的操作。

選擇使用任何編輯器建立以下java程式在 C:/> JAVA

Java8Tester.java
import java.time.ZonedDateTime;
import java.time.ZoneId;

public class Java8Tester {
   public static void main(String args[]){
      Java8Tester java8tester = new Java8Tester();
      java8tester.testZonedDateTime(); 
   }

   public void testZonedDateTime(){
      // Get the current date and time
      ZonedDateTime date1 = ZonedDateTime.parse("2007-12-03T10:15:30+05:30[Asia/Karachi]");  
      System.out.println("date1: " + date1);
      ZoneId id = ZoneId.of("Europe/Paris");
      System.out.println("ZoneId: " + id);		 
	  ZoneId currentZone = ZoneId.systemDefault();
	  System.out.println("CurrentZone: " + currentZone);	   
   }	
}

驗證結果

使用javac編譯器編譯如下類

C:\JAVA>javac Java8Tester.java

現在執行Java8Tester看到的結果

C:\JAVA>java Java8Tester

看到結果。

date1: 2007-12-03T10:15:30+05:00[Asia/Karachi]                           
ZoneId: Europe/Paris                                                     
CurrentZone: Etc/UTC