timezone - How to convert date and time from one time zone to another in when GMT format is given in android -


i have particular date , time of +10:00 gmt (australia/melbourne)which coming google api in following format :-

2015-05-12t14:00:00.000+10:00

now, want convert above time according device current time zone.

for example :-

the above time in +5:30 gmt (india) should 2015-05-12 9:30:00

how can achieve ?

my below code :-

    simpledateformat sourceformat = new simpledateformat("yyyy-mm-dd hh:mm:ss");     sourceformat.settimezone(timezone.gettimezone("gmt"));     date parsed = null;     try {         parsed = sourceformat.parse("2015-05-12 14:00:00");     } catch (parseexception e1) {         // todo auto-generated catch block         e1.printstacktrace();     } // => date in utc      timezone tz = timezone.gettimezone(timezone.getdefault().getid());     simpledateformat destformat = new simpledateformat("yyyy-mm-dd hh:mm:ss");     destformat.settimezone(tz);      string result = destformat.format(parsed);      system.out.println(result); 

but result 2015-05-12 19:30 wrong..

referring this think wrong gettimezone("gmt")

you should use gettimezone("gmt+10:00")); because gmt +/-0:00

have @ doc posted :)


Comments

Popular posts from this blog

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -