Localizing dates in android -



Localizing dates in android -

after reading accepted reply date formatting based on user locale on android german, tested following:

@override protected void onresume() { super.onresume(); string dateofbirth = "02/26/1974"; simpledateformat sdf = new simpledateformat("mm/dd/yyyy"); date date = null; seek { date = sdf.parse(dateofbirth); } grab (parseexception e) { // handle exception here ! } // localized date formats dateformat dateformat = android.text.format.dateformat.getdateformat(getapplicationcontext()); string s = dateformat.format(date); datetv.settext(s); }

here dateofbirth english language date. if alter phone's language high german however, see 02.26.1974. according http://en.wikipedia.org/wiki/date_format_by_country, proper localized high german date format dd.mm.yyyy, hoping see "26.02.1974".

this leads question, there way localize dates or manual process must pore through app dates, times, etc.?

string dateofbirth = "02/26/1974"; simpledateformat sdf = new simpledateformat("mm/dd/yyyy"); date date = null; seek { date = sdf.parse(dateofbirth); } grab (exception e) { // handle exception here ! } // localized date formats log.i(this,"sdf default: "+new simpledateformat().format(date)); // using phone locale dateformat dateformat = dateformat.getdateinstance(dateformat.default, locale.us); log.i(this,"dateformat default: "+dateformat.format(date)); dateformat = dateformat.getdateinstance(dateformat.default, locale.german); log.i(this,"dateformat high german default: "+dateformat.format(date)); dateformat = dateformat.getdateinstance(dateformat.default, locale.chinese); log.i(this,"dateformat chinese default: "+dateformat.format(date)); dateformat = dateformat.getdateinstance(dateformat.short, locale.us); log.i(this,"dateformat short: "+dateformat.format(date)); dateformat = dateformat.getdateinstance(dateformat.short, locale.german); log.i(this,"dateformat high german short: "+dateformat.format(date)); dateformat = dateformat.getdateinstance(dateformat.short, locale.chinese); log.i(this,"dateformat chinese short: "+dateformat.format(date));

output is:

sdf default: 26.02.74 0:00 dateformat default: feb 26, 1974 dateformat high german default: 26.02.1974 dateformat chinese default: 1974-2-26 dateformat short: 2/26/74 dateformat high german short: 26.02.74 dateformat chinese short: 74-2-26

android date localization

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -