How do I parse a standard date into GMT?

前端 未结 3 1362
再見小時候
再見小時候 2021-01-23 17:11

Can someone show me a piece of java code that parses this date:

2009-08-05

INTO THIS GMT DATE:

2009/217:00:00

====

what i have so far is:

相关标签:
3条回答
  • 2021-01-23 17:54

    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);
    
    0 讨论(0)
  • 2021-01-23 17:58
    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

    0 讨论(0)
  • 2021-01-23 18:01
    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.

    0 讨论(0)
提交回复
热议问题