In one of my module I have to achieve following.
I am getting date from server in yyyy-MM-dd'T'HH:mm:ss'Z' format. I have to convert this date and current date in PST and then show difference between those two in hours/mins/seconds.
For converting current time into PST I have written following code
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("America/Los_Angeles"));
Date currentLocalTime = cal.getTime();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", LocaleManager.getLocale());
TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
format.setTimeZone(tz);
String localTime = format.format(currentLocalTime);
Date currentDate = format.parse(localTime);
Here current time is getting converted into string (localTime in code) but when I am parsing this string to get Date object, I am getting date in my timezone only.
My question is if formatter is formatting date in different timezone then while parsing why same date is not being converted into Date object?
Is there any other way to get difference between two dates (current and once received from server) in milliseconds?