vij*_*jay 5 java date jodatime
我试图从字符串转换为localdate(JODA TIME),但它给我错误
String theDate = w.getPSDate(); == 6/03/2013
LocalDate ld = new LocalDate(theDate);
System.out.println(ld);
Run Code Online (Sandbox Code Playgroud)
出于某种原因,我必须使用字符串而不是日期.我想打印日期为(06/03/2013).代码中的错误是什么?
错误
Exception in thread "main" java.lang.IllegalArgumentException: Invalid format: "06/03/2013" is malformed at "/03/2013"
at org.joda.time.format.DateTimeFormatter.parseMillis(DateTimeFormatter.java:747)
at org.joda.time.convert.StringConverter.getPartialValues(StringConverter.java:87)
at org.joda.time.LocalDate.<init>(LocalDate.java:406)
at org.joda.time.LocalDate.<init>(LocalDate.java:354)
at Date.GetDate.main(GetDate.java:94)
Run Code Online (Sandbox Code Playgroud)
Java结果:1
用一个DateTimeFormatter代替:
// Are you sure it's 6/03/2013 rather than 06/03/2013? dd would be nicer...
DateTimeFormatter formatter = DateTimeFormat.forPattern("d/MM/yyyy");
LocalDate date = formatter.parseLocalDate(text);
Run Code Online (Sandbox Code Playgroud)