【发布时间】:2012-02-19 21:50:05
【问题描述】:
如果我有一个File 对象,我怎样才能以这种 GMT 格式获取此文件的lastModified() 日期:Mon, 23 Jun 2011 17:40:23 GMT。
例如,当我在文件上调用 java 方法 lastModified() 并使用 DateFormat 对象为 getDateTimeInstance(DateFormat.Long, DateFormat.Long) 并将 TimeZone 设置为 GMT 时,文件日期以不同的格式显示:
File fileE = new File("/Some/Path");
Date fileDate = new Date (fileE.lastModified());
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.Long, DateFormat.Long);
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
System.out.println("file date " + dateFormat.format(fileDate));
以这种格式打印:
January 26, 2012 7:11:46 PM GMT
我觉得我已经接近上面的格式了,我只是错过了这一天。我必须改用SimpleDateFormat 对象吗?
【问题讨论】:
标签: java date-format simpledateformat gmt