Oracle to Date

to_char(datefield, 'yyyy-mm-dd hh24:mi:ss')

to_date(to_char(sysdate, 'yyyy-mm-dd')||' 20:30:00', 'yyyy-mm-dd hh24:mi:ss')

select to_char((systimestamp at time zone 'GMT'), 'YYYY-MM-DD')||'T'||to_char((systimestamp at time zone 'GMT'), 'HH24:MI:SSxFF')||'Z' from dual;

  String test1 = "2014-06-13T04:00:00.000Z";
	   SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
	   Date date = format.parse(test1);
	   System.out.println(date);

 

In the pattern, the inclusion of a 'z' date-time component indicates that timezone format needs to conform to the General time zone "standard", examples of which arePacific Standard Time; PST; GMT-08:00.

A 'Z' indicates that the timezone conforms to the RFC 822 time zone standard, e.g.-0800.

I think you need a DatatypeConverter ...

@Test public void testTimezoneIsGreenwichMeanTime() throws ParseException { final Calendar calendar = javax.xml.bind.DatatypeConverter.parseDateTime("2010-04-05T17:16:00Z"); TestCase.assertEquals("gotten timezone", "GMT+00:00", calendar.getTimeZone().getID()); }

 

Java doesn't parse ISO dates correctly.

Similar to McKenzie's answer.

Just fix theZbefore parsing.

Code

String string = "2013-03-05T18:05:05.000Z"; String defaultTimezone = TimeZone.getDefault().getID(); Date date = (new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")).parse(string.replaceAll("Z$", "+0000")); System.out.println("string: " + string); System.out.println("defaultTimezone: " + defaultTimezone); System.out.println("date: " + (new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")).format(date));

Result

string: 2013-03-05T18:05:05.000Z defaultTimezone: America/New_York date: 2013-03-05T13:05:05.000-0500

 

你可能感兴趣的:(Oracle to Date)