当前位置: 技术问答>java相关
如何将获取的格林威治时间转换为本地时区的时间?急……
来源: 互联网 发布时间:2015-10-04
本文导语: 现在已知格林威治时间,已知当前的时区,如何将格林威治时间转化为本地时区的时间? 可以将当前的时区和微软的Window2000系统时区进行对应么?如何实现 自己测试得到的offset是毫秒值,不知该如何格林威治时间进...
现在已知格林威治时间,已知当前的时区,如何将格林威治时间转化为本地时区的时间?
可以将当前的时区和微软的Window2000系统时区进行对应么?如何实现
自己测试得到的offset是毫秒值,不知该如何格林威治时间进行转化。
各位大虾如遇到过相似的问题,请给个思路吧。谢谢
可以将当前的时区和微软的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
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()) );
是这样吗?
这很好办啊
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);
Calendar cal=Calendar.getInstance(timeZoneLondon );
cal.set(2002,8,2);//2002-09-02
TimeZone timeZoneshanghai = TimeZone.getTimeZone("Asia/Shanghai");//北京时间
cal.setTimeZone(timeZoneshanghai);
|
wjmmml曾经贴个一个帖子,说到时间格式转换的,你搜索一下看看
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。