Date 的相关问题

来源:3-6 使用 Date 和 SimpleDateFormat 类表示时间

竹墨残香烟花冷

2016-06-17 14:48

import java.util.Date ; public class HelloWorld{    public static void main(String[] args){        Date  day = new Date();        System.out.println(day);        }       } //结果为 Fri Jun 17 06:47:06 UTC 2016 这是美国时间吧  如果要显示为我国时间  该怎么弄呢

写回答 关注

3回答

  • Sunny_Girl
    2016-06-17 15:46:46

    JAVA中将UTC时间转换为本地时间的方法,其他的时区转换与此类似。

    网上找的,可以试试

    public static String utc2Local(String utcTime, String utcTimePatten,
    String localTimePatten) {
    SimpleDateFormat utcFormater = new SimpleDateFormat(utcTimePatten);
    utcFormater.setTimeZone(TimeZone.getTimeZone("UTC"));//时区定义并进行时间获取
    Date gpsUTCDate = null;
    try {
    gpsUTCDate = utcFormater.parse(utcTime);
    } catch (ParseException e) {
    e.printStackTrace();
    }
    SimpleDateFormat localFormater = new SimpleDateFormat(localTimePatten);
    localFormater.setTimeZone(TimeZone.getDefault());
    String localTime = localFormater.format(gpsUTCDate.getTime());
    return localTime;
    }

     

  • 竹墨残香烟花冷
    2016-06-17 15:22:03

    并没有  

  • lvanli
    2016-06-17 15:16:28

    Data获取的你当时运行程序系统的信息

    检查一下你运行系统的系统时间是不是已经到美国去了

Java入门第三季

Java中你必须懂得常用技能,不容错过的精彩,快来加入吧

409780 学习 · 4339 问题

查看课程

相似问题