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.sql.Timestamp ;
  10.  
  11. /* Name of the class has to be "Main" only if the class is public. */
  12. class Ideone
  13. {
  14. public static void main (String[] args) throws java.lang.Exception
  15. {
  16.  
  17. java.sql.Timestamp ts = // Avoid using this badly-designed legacy class if at all possible.
  18. Timestamp // You can convert back-and-forth between legacy and modern classes.
  19. .from( // New method added to legacy class to convert from modern class.
  20. OffsetDateTime // Represents a moment with an offset-of-UTC, a number of some hours-minutes-seconds ahead or behind UTC.
  21. .parse( "2019-01-22T13:09:54.620-05:00" ) // Text in standard ISO 8601 format can be parsed by default, without a formatting pattern.
  22. .toInstant() // Adjust from an offset to UTC (an offset of zero) by extracting an `Instant`.
  23. ) // Returns a `Timestamp` object. Same moment as both the `OffsetDateTime` and `Instant` objects.
  24. ;
  25.  
  26. System.out.println( "ts.toString(): " + ts ) ;
  27. }
  28. }
Success #stdin #stdout 0.16s 2184192KB
stdin
Standard input is empty
stdout
ts.toString(): 2019-01-22 18:09:54.62