My date format is something like this
2013-05-07 18:56:57 (yyyy-MM-dd hh:mm:ss)
I want the output as following.
2013-05-07T06:17:55.827Z
Is there a simple way than using big functions ?
The T is just a literal to separate the date from the time, and the Z means “zero hour offset” also known as “Zulu time” (UTC). If your strings always have a “Z” you can use: SimpleDateFormat format = new SimpleDateFormat( “yyyy-MM-dd'T'HH:mm:ss).
The ToUniversalTime method converts a DateTime value from local time to UTC. To convert the time in a non-local time zone to UTC, use the TimeZoneInfo. ConvertTimeToUtc(DateTime, TimeZoneInfo) method. To convert a time whose offset from UTC is known, use the ToUniversalTime method.
Calendar calendar = new GregorianCalendar(TimeZone. getTimeZone("GMT")); DateFormat formatter = new SimpleDateFormat("dd MMM yyyy HH:mm:ss z"); formatter. setTimeZone(TimeZone.
Try this:
date("Y-m-d\TH:i:s.000\Z", strtotime("2013-05-07 18:56:57"));
This should give the proper ISO8601 date/time in Z(ulu) timezone:
str_replace('+00:00', 'Z', gmdate('c'))
To do a date conversion:
str_replace('+00:00', 'Z', gmdate('c', strtotime('2013-05-07 18:56:57')))
To have the additional .000
(which is useless imho):
str_replace('+00:00', '.000Z', gmdate('c', strtotime('2013-05-07 18:56:57')))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With