Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. public class ZoneExample {
  2. public static void main(String[] args) {
  3. // systemDefault metodu ile JVM varsayılan olarak mevcut saat dilimini işletim sistemi üzerinden alır.
  4. ZoneId defaultZone = ZoneId.systemDefault();
  5. System.out.println(defaultZone); // Çıktı : Asia/Istanbul
  6.  
  7. // of metodu ile özelleştirilmiş saat dilimi elde edebiliriz.
  8. ZoneId customZone = ZoneId.of("Europe/Istanbul");
  9. System.out.println(customZone); // Çıktı : Europe/Istanbul
  10.  
  11. // LocalDateTime gibi çalışır ancak içerisinde saat diliminide barındırır.
  12. ZonedDateTime now = ZonedDateTime.now();
  13. System.out.println(now); // Çıktı : 2019-08-07T15:14:53.248355900+03:00[Asia/Istanbul]
  14.  
  15. // Şuanda Amerika'daki saatin kaç olduğuna bakalım.
  16. ZoneId losAngeles = ZoneId.of("America/Los_Angeles");
  17. ZonedDateTime zonedDateTimeInAmerica = ZonedDateTime.now(losAngeles);
  18. System.out.println(zonedDateTimeInAmerica); // Çıktı : 2019-08-07T05:14:53.248355900-07:00[America/Los_Angeles]
  19.  
  20. // Los Angeles eyalati ile aramızdaki saat farkına bakalım;
  21. System.out.println(now.getHour() - zonedDateTimeInAmerica.getHour()); // Çıktı : 10
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement