When people call YYYYDDD a Julian Date
I've a developer and quite often I have clients asking for a date in Julian date format, and normally this is followed with 'you know the day number format'. What they are really after is a thing called an Ordinal Date which is all explained here http://en.wikipedia.org/wiki/ISO_8601#Ordinal_dates. If every person is told that its not a Julian date but an ordinal date, and we no long have the confusion, the trees will suddenly be greener and all cars will run on a thing called Crukshuka that is so environmentally friendly it will make the trees grow faster!
If I ask a developer to put in some code to do a Julian date, I will either get a huge method copied from the internet, or some very odd and obscure code that will convert a date. But there is an easier way!
JodaDate to the rescue
Joda is a fantastic date and time library. It contains everything a person would ever need for date/time manipulation and formatting. How easy is it to output an ordinal date?
import org.joda.time.LocalDate;
import org.joda.time.format.ISODateTimeFormat;
...
public String getDateYYYYDDD() {
return LocalDate.now().toString(ISODateTimeFormat.basicOrdinalDate());
}
And thats it. All done and in one line of code (well 3 really).
No comments:
Post a Comment