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. int dayOfYear = 308 ;
  19. Year y = Year.of( 2018 ) ;
  20. LocalDate ld = y.atDay( dayOfYear ) ;
  21.  
  22. System.out.println( "dayOfYear: " + dayOfYear + " at year: " + y + " = " + ld ) ;
  23.  
  24. LocalDate ld2 = LocalDate.parse( "2018-308" ) ;
  25.  
  26. }
  27. }
Runtime error #stdin #stdout #stderr 0.23s 34636KB
stdin
Standard input is empty
stdout
dayOfYear: 308 at year: 2018 = 2018-11-04
stderr
Exception in thread "main" java.time.format.DateTimeParseException: Text '2018-308' could not be parsed at index 7
	at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949)
	at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851)
	at java.time.LocalDate.parse(LocalDate.java:400)
	at java.time.LocalDate.parse(LocalDate.java:385)
	at Ideone.main(Main.java:24)