fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.time.format.*;
  4. import java.lang.*;
  5. import java.time.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. String s = "01/2019"; // janeiro de 2019
  13. // usando os campos errados: "m" minúsculo e "Y" maiúsculo
  14. DateTimeFormatter parser = DateTimeFormatter.ofPattern("mm/YYYY");
  15. YearMonth mesAno = YearMonth.parse(s, parser);
  16. }
  17. }
Runtime error #stdin #stdout #stderr 0.18s 2184192KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Exception in thread "main" java.time.format.DateTimeParseException: Text '01/2019' could not be parsed: Unable to obtain YearMonth from TemporalAccessor: {MinuteOfHour=1, WeekBasedYear[WeekFields[SUNDAY,1]]=2019},ISO of type java.time.format.Parsed
	at java.time.format.DateTimeFormatter.createError(DateTimeFormatter.java:1920)
	at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1855)
	at java.time.YearMonth.parse(YearMonth.java:295)
	at Ideone.main(Main.java:15)
Caused by: java.time.DateTimeException: Unable to obtain YearMonth from TemporalAccessor: {MinuteOfHour=1, WeekBasedYear[WeekFields[SUNDAY,1]]=2019},ISO of type java.time.format.Parsed
	at java.time.YearMonth.from(YearMonth.java:263)
	at java.time.format.Parsed.query(Parsed.java:226)
	at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851)
	... 2 more
Caused by: java.time.temporal.UnsupportedTemporalTypeException: Unsupported field: Year
	at java.time.temporal.TemporalAccessor.range(TemporalAccessor.java:174)
	at java.time.temporal.TemporalAccessor.get(TemporalAccessor.java:218)
	at java.time.YearMonth.from(YearMonth.java:260)
	... 4 more