getting the wrong timezone in java / android -


this question has answer here:

string = 26/8/2013 15:59; 

i want convert date gmt, after applying below code, eest time rather gmt.

dateformat df = new simpledateformat("dd/mm/yyyy h:m"); df.settimezone(timezone.gettimezone("utc")); df.parse(newdate); log.i(tag, df.parse(newdate).tostring()); 

output :

mon aug 26 18:59:00 eest 2013 

whats wrong ?

your parsing correct, different locale time zone used display when making tostring(). used formatted output demonstrate correct format . here details example:

final string time = "26/8/2013 15:59"; timezone timezone = timezone.gettimezone("utc"); final string request_date_format = "dd/mm/yyyy h:m";  dateformat format = new simpledateformat(request_date_format); date localdate = format.parse(time);  // localdate.tostring() // print. mon aug 26 15:59:00 eest 2013  calendar cal = calendar.getinstance(timezone); cal.settime(localdate);  format.settimezone(timezone); final string utctime = format.format(cal.gettime()); // print. 26/08/2013 12:59 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -