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.text.ParseException;
  8. import java.text.SimpleDateFormat;
  9. import java.time.LocalDate;
  10. import java.time.Month;
  11. import java.time.ZoneOffset;
  12. import java.util.TimeZone;
  13.  
  14.  
  15. /* Name of the class has to be "Main" only if the class is public. */
  16. class Ideone
  17. {
  18. public static void main (String[] args) throws java.lang.Exception
  19. {
  20. System.out.println( Runtime.version() );
  21.  
  22. SimpleDateFormat billingDateFormatter = new SimpleDateFormat( "MMM d, yyyy" );
  23. billingDateFormatter.setTimeZone( TimeZone.getTimeZone( "Asia/Tokyo" ) );
  24. System.out.println( billingDateFormatter.getTimeZone() ); // Verify the time zone.
  25. java.util.Date d = null;
  26. try
  27. {
  28. d = billingDateFormatter.parse( "Dec 1, 2014" );
  29. }
  30. catch ( ParseException e )
  31. {
  32. e.printStackTrace();
  33. }
  34. LocalDate ld = d.toInstant().atOffset( ZoneOffset.UTC ).toLocalDate();
  35. LocalDate expected = LocalDate.of( 2014 , Month.DECEMBER , 1 );
  36. boolean metExpectations = ld.equals( expected );
  37.  
  38. System.out.println( "d = " + d );
  39. System.out.println( "ld = " + ld );
  40. System.out.println( "expected = " + expected );
  41. System.out.println( "metExpectations = " + metExpectations );
  42. }
  43. }
Success #stdin #stdout 0.25s 41420KB
stdin
Standard input is empty
stdout
12.0.1+12
sun.util.calendar.ZoneInfo[id="Asia/Tokyo",offset=32400000,dstSavings=0,useDaylight=false,transitions=10,lastRule=null]
d = Sun Nov 30 15:00:00 GMT 2014
ld = 2014-11-30
expected = 2014-12-01
metExpectations = false