Need help?

I'm available for remote short term contracting or consultancy work. Please check out my LinkedIn profile for more details on my experience.

Please feel free to use the form below to contact me.

String to Date Formatting Using Java (Android)

Have you been trying to find a quick and easy way to format dates from a String? It can be quite tricky with Java (if you're new to it). So, I'm going to go through a few very simple steps to accomplish just that.

Here's the full piece of code:

String dateStr = "04/05/2010";

SimpleDateFormat curFormater = new SimpleDateFormat("dd/MM/yyyy");
Date dateObj = curFormater.parse(dateStr);
SimpleDateFormat postFormater = new SimpleDateFormat("MMMM dd, yyyy");

String newDateStr = postFormater.format(dateObj);

And now I'll take you through the important pieces of the code step by step.

String dateStr = "04/05/2010";

This is just the string that's holding the date, which we are going to parse.

SimpleDateFormat curFormater = new SimpleDateFormat("dd/MM/yyyy");
Date dateObj = curFormater.parse(dateStr);

The first line instantiates a SimpleDateFormat object and tells it the format it should be looking for to parse. In this case it's dd/MM/yyyy which is identical to our date that we want to parse (04/05/2010).

The second line parses the date string and returns a Date object, which we'll be using later to format the date.

SimpleDateFormat postFormater = new SimpleDateFormat("MMMM dd, yyyy");

String newDateStr = postFormater.format(dateObj);

And finally, we setup another SimpleDateFormat object for the new date format. We then call the format method and pass in the Date object that we created earlier. This returns a string with the newly created date format (ie. May 04, 2010).

Nice and user friendly!

jon | May 04, 2010 | Comments (9)


cheap ray ban,
softball bats,
christian louboutin shoes,
tory burch sale,
nike mercurial,
timberland boots,
jordan release dates,
tory burch sale,
tommy hilfiger outlet,
ugg australia,
louis vuitton handbags,
calvin kleins outlet,
christian louboutin outlet,
air jordan 2015,
oakley sunglasses cheap,
oakley vault,
oakley sunglasses outlet,
swarovski crystal,
knockoff handbags,
shoes outlet,
cheap basketball shoes,
chanel handbags,
true religion jeans,
abercrombie kids,
hermes belt,
gucci outlet,
chanel bags,
ray ban sunglasses,
rolex watches,
glasses frames,
glasses online,
michael kors handbags clearance,
ray bans,
flat iron,
converse outlet,
ferragamo outlet,
gucci belts,
hollister clothing store,
north face jackets,
the north face jackets,
burbery outlet store,
polo ralph lauren outlet,
polo ralph lauren outlet online,
ralph lauren outlet,
insanity calendar,
jimmy choo outlet,
cheap jordans,
juicy couture,
juicy couture outlet,
kate spade outlet online,
louis vuitton outlet online,
michael kors purses,
michael kors handbags clearance,
michael kors outlet online sale,
michael kors,
michael kors outlet online sale,
north face outlet,
oakley outlet,
pandora charms,
prada outlet,
prada shoes for men,
ray ban sunglasses outlet,
omega watches,
swarovski outlet,
the north face outlet,
tiffany and co outlet,
tiffany's jewelry,
cheap true religion,
true religion jeans women,
ugg boots clearance,
uggs on sale,
ugg boots,
ugg outlet,
oakley sunglasses,
cheap oakley sunglasses,
ralph lauren outlet online,
ralph lauren outlet,
burberry outlet,
toms outlet,
toms shoes,
christian louboutin shoes,
tory burch sale,
gucci handbags,
longchamp handbags,
abercrombie and fitch,
hollister clothing store,
hermes belt,
baseball jerseys,
dre beats,
beats by dre,
ray ban,
michael kors,
michael kors handbags,
marc jacobs handbags,
louis vuitton bags,
ralph lauren uk,
free running,
replica watches,
wedding dress,
pandora uk,
thomas sabo uk,
swarovski uk,
air huarache,
roshe run,
the north face,
louis vuitton,
air jordans,
retro jordans,
air jordan shoes,
nike factory outlet,
nike store,
nike outlet,
nike air max 2014,
air max 2015,
nike air max,
free run,
nike free 5.0,
supra footwear,
new balance shoes,
mont blanc,
mcm handbags,
bottega veneta,
soccer shoes,
celine bags,
roshe runs,
nike roshe run,
vans outlet,
timberland shoes,
ipad cases,
softball bats,
louis vuitton outlet,
burberry outlet,
louboutin shoes,
christian louboutin outlet,
louis vuitton,
prada handbags,
michael kors clearance,
michael kors outlet online sale,
tommy hilfiger kids,
mcm world wide,
moncler outlet,
kate spade outlet,
barbour womens,
ferragamo shoes,
canada goose sale,
louis vuitton,
burberry outlet online,
juicy couture clothes ,
north face,
barbour jacket sale,
beats by dre outlet,
louis vuitton sale,
gucci shoes outlet,
longchamp outlet,
moncler outlet online,
ralph lauren polos,
michael kors handbags,
monster beats,
coach outlet online,,
coach store outlet online,
michael kors outlet,
coach factory outlet,
oakley outlet,
nike jordan shoes,
woolrich outlet,
coach outlet online,
coach outlet online usa,
gucci shoes uk,
coach black friday,
michael kors outlet online,
gucci bags,
the north face outlet online,
ugg boots,
ray ban outlet,
toms outlet,
Comment by www - May 18, 2015 @ 10:04 pm
Muito bom, me ajudou muito. Obrigado. Seria realmente ótimo se o manual oficial do Android ensinasse de maneira que fosse fácil de entender.
Comment by Leticia - November 11, 2014 @ 3:18 pm
Hey... everybody is working fine but me. I got unparesable exception when tried to parse new Date() with all of yours String Patterns. Can explain me ?
Comment by Configurer - December 17, 2013 @ 5:21 am
Thanks very very helpful
Comment by Orett - September 06, 2013 @ 9:58 am
thanks very helpfully
Comment by Fadi Mallat - March 21, 2012 @ 5:55 am
thank u
Comment by John Code - March 21, 2012 @ 5:54 am
Awesome. Thank you.
The only one I could find in the web in this subject. Clear, clean and actually works.
I hope Google/Android would learn from you !
Comment by Ahmad - July 07, 2011 @ 5:29 pm
Thanks, this was pretty handy.
Comment by Johan - May 27, 2011 @ 12:21 pm
fantastic! why can't the official Android manual be so clear and easy to understand?
Comment by Dominik - May 12, 2011 @ 2:39 pm

Name (required)
Email (will not be published) (required)