fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. import java.time.* ;
  8. import java.time.format.* ;
  9.  
  10. /* Name of the class has to be "Main" only if the class is public. */
  11. class Ideone
  12. {
  13. public static void main (String[] args) throws java.lang.Exception
  14. {
  15.  
  16. Instant instant = Instant.ofEpochMilli( 1_564_088_400_000L ) ;
  17.  
  18. ZoneId z = ZoneId.of( "America/Montreal" ) ;
  19. LocalDate today = LocalDate.now( z ) ;
  20.  
  21. ZonedDateTime zdt = instant.atZone( z ) ;
  22.  
  23. DayOfWeek dow = zdt.getDayOfWeek() ;
  24.  
  25.  
  26. System.out.println( "instant.toString(): " + instant ) ;
  27. System.out.println( "zdt.toString(): " + zdt ) ;
  28. System.out.println( "dow.toString(): " + dow ) ;
  29.  
  30. ZoneOffset offset = ZoneOffset.UTC ; // Constant for UTC (an offset of zero hours-minutes-seconds).
  31. OffsetDateTime odt = instant.atOffset( offset ) ;
  32.  
  33.  
  34. // When viewed with a time zone farther to the east, more ahead of UTC, we see Friday rather than Thursday.
  35. System.out.println(
  36.  
  37. Instant // Represent a moment in UTC.
  38. .ofEpochMilli( // Parse your count-from-epoch 1970-01-01T00:00:00Z.
  39. 1_564_088_400_000L // Use underscores where you like, to make numeric literals more readable.
  40. ) // Returns an `Instant` object.
  41. .atZone( // Adjust from UTC to some time zone.
  42. ZoneId.of( "Asia/Tokyo" ) // Specify time zone using `Continent/Region` format, never 2-4 letter pseudo-zones such as `EST` or `CST` or `IST`.
  43. ) // Returns a `ZonedDateTime` object.
  44. .getDayOfWeek() // Returns a `DayOfWeek` object.
  45. .getDisplayName( // Generate automatically-localized string for the name of the day-of-week.
  46. TextStyle.FULL , // How long or abbreviated.
  47. Locale.US // Locale determines (a) human language for translation, and (b) cultural norms for issues such as abbreviation, punctuation, capitalization.
  48. )
  49. );
  50. }
  51. }
Success #stdin #stdout 0.16s 39880KB
stdin
Standard input is empty
stdout
instant.toString(): 2019-07-25T21:00:00Z
zdt.toString(): 2019-07-25T17:00-04:00[America/Montreal]
dow.toString(): THURSDAY
Friday