Chinaunix首页 | 论坛 | 博客
  • 博客访问: 369662
  • 博文数量: 100
  • 博客积分: 2586
  • 博客等级: 少校
  • 技术积分: 829
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-09 15:20
个人简介

我是一个Java爱好者

文章分类

全部博文(100)

文章存档

2014年(2)

2013年(7)

2012年(2)

2010年(44)

2009年(28)

2008年(17)

我的朋友

分类: Java

2013-11-06 18:04:26

/**
  * Get relative millisecond offset of two dates in different time zones.
  * Note that the offset value is calculated as the two dates compared in a
  * same time zone.
  *
  * @param date1
  *            The first date.
  * @param timeZone1
  *            The first time zone which the first date is in.
  * @param date2
  *            The second date.
  * @param timeZone2
  *            The second time zone which the second date is in.
  * @return Millisecond offset value between the two dates. the value 0 if
  *         date2 is equal to date1; a value greater than 0 if date2 is after
  *         date1; and a value less than 0 if date2 is before date1.
  */
 public static long getDatesOffsetWithTimeZone(Date date1, TimeZone timeZone1, Date date2,
   TimeZone timeZone2)
 {
  long timeZoneOffset = timeZone2.getOffset(date2.getTime())
    - timeZone1.getOffset(date1.getTime());

  // The time millisecond offset between the two dates.
  long millisOffset = date2.getTime() - date1.getTime();

  // The relative time millisecond offset in a same time zone.
  long timeOffset = millisOffset - timeZoneOffset;

  return timeOffset;
 }

阅读(1320) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~