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. String input = "2020-01-31 04:38:00".replace( " " , "T" ) ;
  17. LocalDateTime ldt = LocalDateTime.parse( input ) ;
  18.  
  19. OffsetDateTime odt = ldt.atOffset( ZoneOffset.UTC ) ;
  20.  
  21. ZoneId z = ZoneId.of( "Africa/Tunis" ) ;
  22. ZonedDateTime zdt = odt.atZoneSameInstant( z ) ;
  23.  
  24. Locale locale = Locale.JAPAN ;
  25. DateTimeFormatter f = DateTimeFormatter.ofLocalizedDateTime( FormatStyle.FULL ).withLocale( locale ) ;
  26. String output = zdt.format( f ) ;
  27.  
  28. System.out.println( "ldt.toString() = " + ldt ) ;
  29. System.out.println( "odt.toString() = " + odt ) ;
  30. System.out.println( "zdt.toString() = " + zdt ) ;
  31. System.out.println( "output = " + output ) ;
  32.  
  33. }
  34. }
Success #stdin #stdout 0.24s 56872KB
stdin
Standard input is empty
stdout
ldt.toString() = 2020-01-31T04:38
odt.toString() = 2020-01-31T04:38Z
zdt.toString() = 2020-01-31T05:38+01:00[Africa/Tunis]
output = 2020年1月31日金曜日 5時38分00秒 中央ヨーロッパ標準時