fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.time.* ;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. Instant instant = Instant.now() ;
  14.  
  15. ZoneOffset offset = ZoneId.of( "Africa/Dar_es_Salaam" ).getRules().getOffset( instant ) ;
  16. OffsetDateTime odt = OffsetDateTime.now( offset ) ;
  17.  
  18. ZoneId zone = ZoneId.of( "Africa/Dar_es_Salaam" ) ;
  19. ZonedDateTime zonedDateTime = ZonedDateTime.now( zone ) ;
  20.  
  21. System.out.println( instant + " | " + instant.getEpochSecond() ) ;
  22. System.out.println( odt + " | " + odt.toEpochSecond() ) ;
  23. System.out.println( zonedDateTime + " | " + zonedDateTime.toEpochSecond() ) ;
  24. }
  25. }
Success #stdin #stdout 0.27s 54036KB
stdin
Standard input is empty
stdout
2023-01-24T14:27:06.416597Z | 1674570426
2023-01-24T17:27:06.478680+03:00 | 1674570426
2023-01-24T17:27:06.487289+03:00[Africa/Dar_es_Salaam] | 1674570426