views:

92

answers:

2

I have been working with a Birthday reminder application for quite some time. During which, I have noticed that contact birthdays are being stored in different formats on different devices. Several of them are given below.

yyyy-MM-dd
yyyy-MM-dd'T'HH:mm:ss'Z'
yyyy-MM-dd'T'HH:mm:ss.SSS'Z'

It took many crashes and bug-reports to figure out these formats.

Now, I am having same problem all over again with dates with no year. This is a valid case and it's supported by google contacts. I own an HTC Desire and these dates are stored in my phone with the following format (--MM-dd).

What I want to know is whether Android has any standard way of storing dates (like birthdays/anniversaries) when no year is specified? According to DateParser, it should take current year but, that's not valid. What can I do to explicitly specify that the year in a date is unknown?

Thanks in advance.

A: 

you need some kind of date parser to handle the several date formats in android

20100715T1043:11Z
2010-07-15T10:43:11Z
20100715104311
2010. july 15.
2010-07-15 10:43:11

Here is a tutorial on how to do this, date parser

ArtWorkAD
Maybe my question was confusing, but I have already written a parser. What I want to know is whether Android has any standard way of storing dates (like birthdays/anniversaries) when no year is specified? I'll update the question to make it more clear.
deltasquare4
+2  A: 

I don't think that Android and by implication the core Java libraries has a way to hold a date with no year since internally the Date class is using an unsigned long from epoch time (1/1/1900). Its up to the developer to handle the weird data like missing year either by using classes with extra properties like "no year" or setting a default which you'll have to handle anytime you deal with one of your dates with no year. And if you need to do complicated date/time math its gets really messy quickly. In which case you may want to look at the Joda-Time library which has things like Partial which can be just a month-day combo.

Morrison Chang