fork(1) 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.temporal.* ;
  9. import java.time.format.* ;
  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. String input = "2012-03-04 00:00:00.0".replace( " " , "T" ) ;
  19.  
  20. LocalDateTime ldt = LocalDateTime.parse( input ) ;
  21. LocalDateTime ldtTruncated = ldt.truncatedTo( ChronoUnit.SECONDS ) ;
  22.  
  23. DateTimeFormatter f = DateTimeFormatter.ofPattern( "uuuu-MM-dd HH:mm:ss" ) ;
  24. String output = ldtTruncated.format( f ) ;
  25.  
  26. System.out.println( "input: " + input ) ;
  27. System.out.println( "ldt: " + ldt ) ;
  28. System.out.println( "ldtTruncated: " + ldtTruncated ) ;
  29. System.out.println( "output: " + output ) ;
  30.  
  31.  
  32. }
  33. }
Success #stdin #stdout 0.22s 34816KB
stdin
Standard input is empty
stdout
input: 2012-03-04T00:00:00.0
ldt: 2012-03-04T00:00
ldtTruncated: 2012-03-04T00:00
output: 2012-03-04 00:00:00