如何将标准日期解析为GMT?

时间:2009-08-10 22:19:31

标签: java date date-format simpledateformat

有人可以给我看一段解析这个日期的java代码:

2009-08-05

到格林威治标准时间:

二百一十七分之二千零九:00:00

====

到目前为止我所拥有的是:

       java.text.SimpleDateFormat format = new SimpleDateFormat("yyyy-mm-dd");

       java.util.Calendar cal = Calendar.getInstance(new SimpleTimeZone(0, "GMT"));
       format.setCalendar(cal);
       java.util.Date date = format.parse(sdate);

但它不起作用

3 个答案:

答案 0 :(得分:8)

以下是您要查找的格式:

Date date = new SimpleDateFormat("yyyy-MM-dd").parse("2009-08-05");
String parsedDate = new SimpleDateFormat("yyyy/D:HH:mm").format(date);

答案 1 :(得分:2)

format.setTimeZone(TimeZone.getTimeZone("GMT"));

至少如何将它设置为GMT。不确定你从2009-08-05获得2009/217的位置

答案 2 :(得分:0)

SimpleDateFormat dateFormatGmt = new SimpleDateFormat("dd:MM:yyyy HH:mm:ss");
    dateFormatGmt.setTimeZone(TimeZone.getTimeZone("GMT"));
    System.out.println(dateFormatGmt.format(new Date())+"");

这会将您当地的时间转换为GMT。