有人能告诉我一块Java代码解析此日期:

2009-08-05

到该GMT DATE:

二百一十七分之二千零九: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);

但其不工作

有帮助吗?

解决方案

下面是你要找的格式为:

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"));

这就是如何将它至少设置为GMT。不知道你在哪里得到二百十七分之二千零九从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())+"");

这将在您的本地时间转换为GMT

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top