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. import java.time.temporal.* ;
  10.  
  11.  
  12. /* Name of the class has to be "Main" only if the class is public. */
  13. class Ideone
  14. {
  15. public static void main (String[] args) throws java.lang.Exception
  16. {
  17.  
  18. ZoneId z = ZoneId.of( "Asia/Kolkata" ) ;
  19. ZonedDateTime zdt = ZonedDateTime.now( z ).truncatedTo( ChronoUnit.MINUTES ) ;
  20.  
  21. String output = zdt.toString() ; // ISO 8601 format, extended to append name of time zone.
  22.  
  23. Locale locale = new Locale( "en" , "IN" ) ; // English language, India culture.
  24. DateTimeFormatter f = DateTimeFormatter.ofLocalizedDateTime( FormatStyle.LONG ).withLocale( locale ) ;
  25. String output2 = zdt.format( f ) ;
  26.  
  27. System.out.println( "output: " + output ) ;
  28. System.out.println( "output2: " + output2 ) ;
  29.  
  30. System.out.println(
  31.  
  32. ZonedDateTime
  33. .now(
  34. ZoneId.of( "Pacific/Auckland" )
  35. )
  36. .format(
  37. DateTimeFormatter
  38. .ofPattern(
  39. "dd MMMM uuuu HH:mm"
  40. )
  41. .withLocale(
  42. Locale.CANADA_FRENCH
  43. )
  44. )
  45.  
  46. );
  47.  
  48.  
  49. }
  50. }
Success #stdin #stdout 0.22s 42388KB
stdin
Standard input is empty
stdout
output: 2019-09-28T02:18+05:30[Asia/Kolkata]
output2: 28 September 2019 at 2:18:00 AM IST
28 septembre 2019 08:48