formatting date in android -


i'm trying display date have new format, i'm using simpledateformat this.

android code

string date = "2013-08-11 20:38 edt"; simpledateformat sf = new simpledateformat("dd mmmm yyyy hh:mm a"); try {     newdate = sf.format(new simpledateformat("yyyy-mm-dd kk:mm z").parse(date)); } catch (parseexception e) {     e.printstacktrace(); } 

it displays : 11 august 2013 08:38 pm

however if run same code in java (as normal java console application)

java

string date = "2013-08-11 20:38 edt"; simpledateformat sf = new simpledateformat("dd mmmm yyyy hh:mm a"); string ldate = sf.format(new simpledateformat("yyyy-mm-dd kk:mm z").parse(date)); system.out.println(ldate); 

it displays : 12 august 2013 06:08 am

this format need display.

p.s. : got warning in android saying

to local formatting use getdateinstance(), getdatetimeinstance(), or gettimeinstance(), or use new simpledateformat(string template, locale locale) example locale.us ascii dates.

so tried adding locale.us simpledateformat again show 11 august 2013 08:38 pm , not 12 august 2013 06:08 am

my question : how display date 12 august 2013 06:08 in android.

your local time ist utc+05:30, android time edt utc-04:00. add 9h30min of difference explaining difference in output.

set android device ist timezone same output.

alternatively, can call settimezone() on dateformat explicitly set timezone use.

it helpful explicitly print timezone information make datetime stamps less ambiguous.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -