Guest User

Untitled

a guest
Aug 15th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. ZoneId nyZone = ZoneId.of("America/New_York");
  2. ZoneId brazilZone = ZoneId.of("America/Recife");
  3.  
  4. LocalDateTime ldtBrazil = LocalDateTime.now(brazilZone);
  5. LocalDateTime ldtNY = LocalDateTime.now(nyZone);
  6.  
  7. Instant instantBrazil = ldtBrazil.toInstant(ZoneOffset.UTC);
  8. Instant instantNY = ldtNY.toInstant(ZoneOffset.UTC);
  9.  
  10. System.out.println("-------LocalDateTime-------");
  11. System.out.println("ldtBrazil : "+ldtBrazil);
  12. System.out.println("ldtNY : "+ldtNY);
  13.  
  14. System.out.println("n-------Instant-------");
  15. System.out.println("instantBrazil: "+instantBrazil);
  16. System.out.println("instantNY : "+instantNY);
  17.  
  18. long milliBrazil = instantBrazil.toEpochMilli();
  19. long milliNY = instantNY.toEpochMilli();
  20.  
  21. System.out.println("n----------Milli----------");
  22. System.out.println("miliBrazil : "+milliBrazil);
  23. System.out.println("miliNY : "+milliNY);
  24.  
  25. Date dateBrazil = Date.from(instantBrazil);
  26. Date dateNY = Date.from(instantNY);
  27.  
  28. System.out.println("n---------Date From Instant---------");
  29. System.out.println("dateBrazil: "+dateBrazil);
  30. System.out.println("dateNY : "+dateNY);
  31.  
  32. System.out.println("n---------Date From Milli---------");
  33. System.out.println("dateBrazil: "+new Date(milliBrazil));
  34. System.out.println("dateNY : "+new Date(milliNY));
  35.  
  36. -------LocalDateTime-------
  37. ldtBrazil : 2016-09-21T22:11:52.118
  38. ldtNY : 2016-09-21T21:11:52.118
  39.  
  40. -------Instant-------
  41. instantBrazil: 2016-09-21T22:11:52.118Z
  42. instantNY : 2016-09-21T21:11:52.118Z
  43.  
  44. ----------Milli----------
  45. miliBrazil : 1474495912118
  46. miliNY : 1474492312118
  47.  
  48. ---------Date From Instant---------
  49. dateBrazil: Wed Sep 21 19:11:52 BRT 2016
  50. dateNY : Wed Sep 21 18:11:52 BRT 2016 //this data must be related to NY LocalDateTime, but reiceved a same date of Brazil.
  51.  
  52. ---------Date From Milli---------
  53. dateBrazil: Wed Sep 21 19:11:52 BRT 2016
  54. dateNY : Wed Sep 21 18:11:52 BRT 2016
  55.  
  56. Instant now = Instant.now();
  57.  
  58. ZoneId zNewYork = ZoneId.of("America/New_York");
  59. ZoneId zRecife = ZoneId.of("America/Recife");
  60.  
  61. ZonedDateTime zdtNewYork = now.atZone( zNewYork );
  62. ZonedDateTime zdtRecife = now.atZone( zRecife );
  63.  
  64. java.util.Date utilDate = java.util.Date.from( zdtNewYork.toInstant() );
  65.  
  66. Instant instant = utilDate.toInstant();
Add Comment
Please, Sign In to add comment