fork(2) 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. import java.time.chrono.* ;
  11. import java.time.zone.* ;
  12.  
  13. /* Name of the class has to be "Main" only if the class is public. */
  14. class Ideone
  15. {
  16. public static void main (String[] args) throws java.lang.Exception
  17. {
  18. String output =
  19. LocalDateTime
  20. .parse(
  21. "2020-02-21 16:36:30.072".replace( " " , "T" )
  22. ) // Returns a `LocalDateTime` object. *Not* a moment, *not* a point on the timeline. Just a date and a time-of-day, nothing more. Lacks context of a time zone or offset-from-UTC.
  23. .atZone( // Lending context to our `LocalDateTime` object to determine a moment by assigning a time zone.
  24. ZoneId.of( "Asia/Kolkata" ) // Currently using an offset of five and a half hours ahead of UTC.
  25. ) // Returns a `ZonedDateTime` object.
  26. .format( // Generates text representing the value of the `ZonedDateTime` object.
  27. DateTimeFormatter.ISO_OFFSET_DATE_TIME // Pre-defined formatter. No need to specify your own formatting pattern. Your desired format complies with the ISO 8601 standard.
  28. ) // Returns a `String`.
  29. ;
  30.  
  31. System.out.println( "output: " + output ) ;
  32. }
  33. }
Success #stdin #stdout 0.16s 39000KB
stdin
Standard input is empty
stdout
output: 2020-02-21T16:36:30.072+05:30