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.  
  10. /* Name of the class has to be "Main" only if the class is public. */
  11. class Ideone
  12. {
  13. public static void main (String[] args) throws java.lang.Exception
  14. {
  15.  
  16. String input = "20141202" ;
  17. DateTimeFormatter f = DateTimeFormatter.BASIC_ISO_DATE ;
  18. LocalDate ld = null;
  19. try{
  20. ld = LocalDate.parse( input , f );
  21. } catch ( DateTimeParseException e ) {
  22. // … Handle error because of bad input.
  23. System.out.println( "error: " + e );
  24. }
  25.  
  26.  
  27. LocalDate oneWeekAgo = ld.minusWeeks( 1 );
  28.  
  29. System.out.println( "input: " + input );
  30. System.out.println( "ld.toString(): " + ld );
  31. System.out.println( "oneWeekAgo.toString(): " + oneWeekAgo );
  32.  
  33.  
  34. }
  35. }
Success #stdin #stdout 0.1s 711680KB
stdin
Standard input is empty
stdout
input: 20141202
ld.toString(): 2014-12-02
oneWeekAgo.toString(): 2014-11-25