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.  
  9. /* Name of the class has to be "Main" only if the class is public. */
  10. class Ideone
  11. {
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14.  
  15. String input = "2017-01-01 00:00:00".replace( " " , "T" ) + "Z" ; // Assuming this input was intended to be in UTC.
  16. Instant instant = Instant.parse( input ) ;
  17.  
  18. ZoneId z = ZoneId.of( "Asia/Kolkata" ) ;
  19. ZonedDateTime zdt = instant.atZone( z ) ;
  20.  
  21. System.out.println( "input: " + input );
  22. System.out.println( "instant.toString(): " + instant );
  23. System.out.println( "zdt.toString(): " + zdt );
  24.  
  25. }
  26. }
Success #stdin #stdout 0.15s 4386816KB
stdin
Standard input is empty
stdout
input: 2017-01-01T00:00:00Z
instant.toString(): 2017-01-01T00:00:00Z
zdt.toString(): 2017-01-01T05:30+05:30[Asia/Kolkata]