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);

解决方案 »

  1.   

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

  2.   

    抄个例子:)
    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
     
      

  3.   

    如果是格林威治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()) );
      

  4.   

    谢谢各位,我把时间浪费在了通过Offset来计算本地时间了,不过另一个问题就是通过getDefault()获取的本地时区如何和Windows2000中的时区表进行对应呢?看了一下TimeZone中的getAvaliableIDs()获取的时区和Windows2000中定义的不太一样,两者定义的方式不同,不知道能不能实现这两者的对应关系?不行的话,只好放弃这个功能.