java.text.DateFormat dateFormatter=java.text.DateFormat.getDateInstance(java.text.DateFormat.FULL,localBeijing); java.text.DateFormat dateFormatterParis=java.text.DateFormat.getDateInstance(java.text.DateFormat.FULL,localFrance); java.util.Date curDate=new java.util.Date(); System.out.println("Display for Beijing office."); //Print the Beijing time zone display name in CN. System.out.println(timeZoneBeijing.getDisplayName(localBeijing)); //Set the time zone of the dateFormatter to Beijing time zone. dateFormatter.setTimeZone(timeZoneBeijing); //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 zong display name in CN. System.out.println(timeZoneParis.getDisplayName(localBeijing)); //Print the Paris time in Chinese. System.out.println(dateFormatter.format(curDate));
System.out.println("\nDisplay for Paris office."); //Print the Beijing time zone display name in French. System.out.println(timeZoneBeijing.getDisplayName(localFrance)); //Set the time zone of dateFormatterParis to Beijing time zone. dateFormatter.setTimeZone(timeZoneBeijing); //Print the formatted date in French. System.out.println(dateFormatterParis.format(curDate)); //Set the time zone of date formatter to Paris time zone. dateFormatterParis.setTimeZone(timeZoneParis); //Print the Paris time zone display name in French. System.out.println(timeZoneParis.getDisplayName(localFrance)); //Print the Paris time in French. System.out.println(dateFormatterParis.format(curDate));
楼上的输出结果是这样的, Display for Beijing office. China Standard Time 2007年3月16日 Central European Time 2007年3月16日Display for Paris office. China Standard Time vendredi 16 mars 2007 Central European Time vendredi 16 mars 2007跟我说的还有些距离. 辛苦了
java.util.Locale localBeijing=java.util.Locale.CHINA;
java.util.Locale localFrance=java.util.Locale.FRANCE;
java.util.TimeZone timeZoneBeijing=java.util.TimeZone.getDefault();
java.util.TimeZone timeZoneParis=java.util.TimeZone.getTimeZone("Europe/Paris");
java.text.DateFormat dateFormatter=java.text.DateFormat.getDateInstance(java.text.DateFormat.FULL,localBeijing);
java.text.DateFormat dateFormatterParis=java.text.DateFormat.getDateInstance(java.text.DateFormat.FULL,localFrance);
java.util.Date curDate=new java.util.Date();
System.out.println("Display for Beijing office.");
//Print the Beijing time zone display name in CN.
System.out.println(timeZoneBeijing.getDisplayName(localBeijing));
//Set the time zone of the dateFormatter to Beijing time zone.
dateFormatter.setTimeZone(timeZoneBeijing);
//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 zong display name in CN.
System.out.println(timeZoneParis.getDisplayName(localBeijing));
//Print the Paris time in Chinese.
System.out.println(dateFormatter.format(curDate));
System.out.println("\nDisplay for Paris office.");
//Print the Beijing time zone display name in French.
System.out.println(timeZoneBeijing.getDisplayName(localFrance));
//Set the time zone of dateFormatterParis to Beijing time zone.
dateFormatter.setTimeZone(timeZoneBeijing);
//Print the formatted date in French.
System.out.println(dateFormatterParis.format(curDate));
//Set the time zone of date formatter to Paris time zone.
dateFormatterParis.setTimeZone(timeZoneParis);
//Print the Paris time zone display name in French.
System.out.println(timeZoneParis.getDisplayName(localFrance));
//Print the Paris time in French.
System.out.println(dateFormatterParis.format(curDate));
Display for Beijing office.
China Standard Time
2007年3月16日
Central European Time
2007年3月16日Display for Paris office.
China Standard Time
vendredi 16 mars 2007
Central European Time
vendredi 16 mars 2007跟我说的还有些距离.
辛苦了
而且现在的GMT时间是一个"YYYY/MM/DD HH:MM:SS"的String型.要转成地区不固定的当地时间.
.........