现在的位置: 首页 > 综合 > 正文

dateformat后时间少了8小时问题

2014年09月05日 ⁄ 综合 ⁄ 共 468字 ⁄ 字号 评论关闭


dateformat后时间少了8小时问题
 经调查刚刚程序里用的format为:
 org.apache.tools.ant.util.DateUtils.format

 源代码如下:
 public static String format(Date date, String pattern)
    {
        DateFormat df = createDateFormat(pattern);
        return df.format(date);
    }

 private static DateFormat createDateFormat(String pattern)
    {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        TimeZone gmt = TimeZone.getTimeZone("GMT");//关键所在
        sdf.setTimeZone(gmt);
        sdf.setLenient(true);
        return sdf;
    }

抱歉!评论已关闭.