0

I have an

i) integer variable called gmtoffset (which is the number of hours/minutes to add/subtract from the base time) and

ii) map object(called result) which contains the timestamp in GMT . I need to iterate into map object and change the timestamp inside the map object by adding/subtracting according to the no of hours in gmtoffset variable.

For e.g, int gmtoffset = 0230 , changedTimestamp = 2013-09-11 01:11:00.1

My final changedTimestamp variable should be 2013-09-11 10:41:00.1

Request help.

4

1 回答 1

0

您可以使用Java 日历SimpleDateFormat来完成这项工作。类似于以下内容:

Date date = <convert your changedTimesetamp to a date, see SimpleDateFormat>
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
cal.setTime(date);
cal.add(Calendar.MINUTE, gmtoffset);

注意:假设 gmtoffset 以分钟为单位……所以 2 小时 30 分钟将是 150 分钟。

于 2013-10-22T01:55:26.137 回答