Domanda

So I am using this class "SimpleDateFormat" so that I can convert number of days in a year to a date, using "DDD". However, I'm not sure if this covers leap years because I don't see an option where I can specify that this year is a leap. If I specify a year, will it already know that it is a leap? I just want to be sure.

Thank You, ejay

È stato utile?

Soluzione

The SimpleDateFormat works well with Leap years in Julian calendar :)

Just in case.... you can set the lenient attribute to false.

 SimpleDateFormat sf=new SimpleDateFormat("ddMMMyyyy");
 sf.setLenient(false);
 sf.parse("29Feb2012");//OK
 sf.parse("29Feb2003");//throws parseException
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top