java格林威治转为本地date_如何将获取的格林威治时间转换为本地时区的时间?急……...

现在已知格林威治时间,已知当前的时区,如何将格林威治时间转化为本地时区的时间?

可以将当前的时区和微软的Window2000系统时区进行对应么?如何实现

自己测试得到的offset是毫秒值,不知该如何格林威治时间进行转化。

各位大虾如遇到过相似的问题,请给个思路吧。谢谢

|

抄个例子:)

import java.util.TimeZone;

import java.util.Date;

import java.util.Locale;

import java.text.DateFormat;

public class DateExample9 {

public static void main(String[] args) {

Locale localeEN = Locale.US;

Locale localeFrance = Locale.FRANCE;

TimeZone timeZoneMiami = TimeZone.getDefault();

TimeZone timeZoneParis = TimeZone.getTimeZone("Europe/Paris");

DateFormat dateFormatter = DateFormat.getDateTimeInstance(

DateFormat.FULL,

DateFormat.FULL,

localeEN);

DateFormat dateFormatterParis = DateFormat.getDateTimeInstance(

DateFormat.FULL,

DateFormat.FULL,

localeFrance);

Date curDate = new Date();

System.out.println("Display for Miami office.");

// Print the Miami time zone display name in English

System.out.println(timeZoneMiami.getDisplayName(localeEN));

// Set the time zone of the dateFormatter to Miami time zone.

dateFormatter.setTimeZone(timeZoneMiami);

// Print the formatted date.

System.out.println(dateFormatter.format(curDate));

// Set the time zone of the date formatter to Paris time zone.

dateFormatter.setTimeZone(timeZoneParis);

// Print the Paris time zone display name in English.

System.out.println(timeZoneParis.getDisplayName(localeEN));

// Print the Paris time in english.

System.out.println(dateFormatter.format(curDate));

System.out.println("nDisplay for Paris office.");

// Print the Miami time zone display name in French

System.out.println(timeZoneMiami.getDisplayName(localeFrance));

// Set the timezone of the

// dateFormatterParis to Miami time zone.

dateFormatterParis.setTimeZone(timeZoneMiami);

// Print the formatted date in French.

燬ystem.out.println(dateFormatterParis.format(curDate));

// Set the timezone of the date formatter to Paris time zone.

dateFormatterParis.setTimeZone(timeZoneParis);

// Print the Paris time zone display name in French.

System.out.println(timeZoneParis.getDisplayName(localeFrance));

// Print the Paris time in French.

System.out.println(dateFormatterParis.format(curDate));

}

}

这个例子的输出是:

Display for Miami office.

Eastern Standard Time

Friday, October 5, 2001 10:28:02 PM EDT

Central European Standard Time

Saturday, October 6, 2001 4:28:02 AM CEST

Display for Paris office.

GMT-05:00

vendredi 5 octobre 2001 22 h 28 GMT-04:00

GMT+01:00

samedi 6 octobre 2001 04 h 28 GMT+02:00

|

如果是格林威治00:00,你要显示成08:00

是这样吗?

这很好办啊

java.util.GregorianCalendar ca = new java.util.GregorianCalendar(java.util.TimeZone.getTimeZone("GMT 00:00"));

ca.set(2002, 9, 1, 00, 00, 00);

java.text.SimpleDateFormat format=new java.text.SimpleDateFormat("yyyy/MM/dd HH:mm");

format.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));

System.out.println( format1.format(ca.getTime()) );

|

TimeZone timeZoneLondon = TimeZone.getTimeZone("Europe/London");//格林威治

Calendar cal=Calendar.getInstance(timeZoneLondon );

cal.set(2002,8,2);//2002-09-02

TimeZone timeZoneshanghai = TimeZone.getTimeZone("Asia/Shanghai");//北京时间

cal.setTimeZone(timeZoneshanghai);

|

wjmmml曾经贴个一个帖子,说到时间格式转换的,你搜索一下看看

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值