new Date()不就得到当地时间了?

解决方案 »

  1.   

    是要把固定值为"2007-03-16 09:30:28"的GMT时间转化为当地时间.要怎么写啊?
      

  2.   

    用java.util.TimeZone啊,详细的使用的情况看java的API文档
      

  3.   


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

  4.   

    楼上的输出结果是这样的,
    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跟我说的还有些距离.
    辛苦了
      

  5.   

    这边的话,不是说要固定的取某个地区的当地时间,能不能把他共通话,不管什么地方都能取到当地时间.
    而且现在的GMT时间是一个"YYYY/MM/DD HH:MM:SS"的String型.要转成地区不固定的当地时间.
    .........