Date handling in Android development
This unusual topic came around quite a few times in the last couple of days, first with our own rss parser, and today with android-xmlrpc.
In our rss parser, we wanted to have as much flexibility as possible, so we could use many types of localized rss pages, that have different date formats.
Here are a few examples, for different date formats:
20100715T1043:11Z
2010-07-15T10:43:11Z
20100715104311
2010. july 15.
2010-07-15 10:43:11
Here is the cheat sheet in the android docs for date syntax.
Today I started working on an xml reader, and I used the android-xmlrpc library. It was hard coded to work with only one kind of date format, luckily, the source code is also included, so it's possible to set up my own flavour of date format.
Here is a little snippet, from our rss date value parser. It works like this: first it tries our custom SimpleDateFormat, than it tries several DateFormats.
- //usually we use this format
- item.getChild(PUB_DATE).setEndTextElementListener(new EndTextElementListener() {
- try {//first try our own format
- mRssItem.mPublicationDate = mSimpleDateFormat.parse(body);
- try {
- mRssItem.mPublicationDate = df.parse(body);
- try {
- mRssItem.mPublicationDate = df.parse(body);
- try {
- mRssItem.mPublicationDate = df.parse(body);
- try {
- mRssItem.mPublicationDate = df.parse(body);
- // TODO log input format error
- }
- }
- }
- }
- }
- }
- });
New tutorials from Helloandroid
Recent Apps
Android on Twitter
-
@Idevicegazette (iDevice Gazette)
GSM-to-Skype bridge lets you lose those roaming fees http://bit.ly/lbRJeh #android
12 years 3 weeks ago -
@tommy_banane (tom b.)
RT @AndroidFavorite: #Android New Desktop Android Market Is Live, Adds Several New Features http://zorr0.nl/lFwXNz
12 years 3 weeks ago -
@dwilliams5 (Dennis Williams)
just completed a runtastic run of 3.02 km in 40 min 11 s with #runtastic #Android App: http://tinyurl.com/5tvrpe3
12 years 3 weeks ago -
@S_Pinz (Spinz!)
RT @Androidheadline: Out of box #LG Optimus 3D got Quadrant 2420 score. Thanks @blink_c #io2011 #android http://twitpic.com/4whkdz
12 years 3 weeks ago -
@tayaitapps (Taya IT)
Next Google TV Looks A Lot Like Android http://t.co/dvlTim3 via @alleyinsider #google #apple #android #tv #honeycomb
12 years 3 weeks ago
Poll
Useful resources
Android Development Projects
- App Development
- Telegram bulk messages sender
- Photo Editing Application
- React Native Developer - part time basis
- Locket App Copy
- Courier app $150 only
- Mobile Application Development - IOS and Android (Rewards for sharing brand ads on social media)
- Android app for sms
- Fitness app project for sale online
- io developer