How do I parse a standard date into GMT?

限于喜欢 提交于 2019-12-02 03:14:12
Tommy

Here is the format you're looking for:

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

That's how to set it to GMT at least. Not sure where you are getting 2009/217 from 2009-08-05

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

This will convert your local time to GMT.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!