Guest User

Untitled

a guest
Jan 20th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. 2012-11-09T00:00:00+01:00
  2.  
  3. 2012-11-08T23:00:00Z
  4.  
  5. // Your input String (with no colons in the timezone portion)
  6. String original = '2012-11-09T00:00:00+0100'
  7.  
  8. // The format to read this input String
  9. def inFormat = new java.text.SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ssZ" )
  10.  
  11. // The format we want to output
  12. def outFormat = new java.text.SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss'Z'" )
  13. // Set the timezone for the output
  14. outFormat.timeZone = java.util.TimeZone.getTimeZone( 'GMT' )
  15.  
  16. // Then parse the original String, and format the resultant
  17. // Date back into a new String
  18. String result = outFormat.format( inFormat.parse( original ) )
  19.  
  20. // Check it's what we wanted
  21. assert result == '2012-11-08T23:00:00Z'
  22.  
  23. // Your input String
  24. String original = '2012-11-09T00:00:00+01:00'
  25.  
  26. // The format to read this input String (using the X
  27. // placeholder for ISO time difference)
  28. def inFormat = new java.text.SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ssX" )
Add Comment
Please, Sign In to add comment