开发者

Get difference in two different timestamps in Blackberry application

开发者 https://www.devze.com 2022-12-12 11:03 出处:网络
I wo开发者_Python百科uld like to know how to calculate difference between two different timezones / timestamps in Blackberry application.

I wo开发者_Python百科uld like to know how to calculate difference between two different timezones / timestamps in Blackberry application.

For e.g. Calculate difference in server timestamp and client timestamp

Please help. Thanks.


Try this code:

class Scr extends MainScreen {
 public Scr() {
  String time1 = "2009-11-27 01:38:05";
  String zone1 = "Pacific/Midway";
  String time2 = "2008-05-01 12:38:05";
  String zone2 = "MST";

  long timeDiff = getTimeDifference(time1, zone1, time2, zone2);
  Date date = new Date(timeDiff);
  add(new LabelField(String.valueOf(date)));
 }

 public long getTimeDifference(String timestamp1, String timezone1,
   String timestamp2, String timezone2) {
  long time1 = getTime(timestamp1, TimeZone.getTimeZone(timezone1));
  long time2 = getTime(timestamp2, TimeZone.getTimeZone(timezone2));
  return time2 - time1;
 }

 public long getTime(String time, TimeZone timeZone) {
  Date formatter = new Date(HttpDateParser.parse(time));
  int offset = timeZone.getRawOffset();
  return formatter.getTime() + offset;
 }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消