I get a response from a other server with a date time like below,
"2017-01-10T18:00:00.000Z"
I want to convert this to standard date time like this, how do i do this ?
"2017-01-10 18:00:00"
is there a standard way of doing this ? or do i have rely on the regular expressions to the decode it ?
NOTE:
most people suggest i use below function
echo date("Y-m-d H:i:s", strtotime("2017-01-10T18:00:00.000Z")) . "\n";**
but output i get is wrong from this function is "2017-01-11 05:00:00" not as "2017-01-11 18:00:00" why ? I want as i said "2017-01-10 18:00:00"
Change YYYY-MM-DD to DD-MM-YYYY In the below example, we have date 2019-09-15 in YYYY-MM-DD format, and we will convert this to 15-09-2019 in DD-MM-YYYY format. $orgDate = "2019-09-15"; $newDate = date("d-m-Y", strtotime($orgDate)); echo "New date format is: ".
Z - Timezone offset in seconds. The offset for timezones west of UTC is negative (-43200 to 50400) c - The ISO-8601 date (e.g. 2013-05-05T16:34:42+00:00) r - The RFC 2822 formatted date (e.g. Fri, 12 Apr 2013 12:01:05 +0200)
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).
Definition and Usage The strtotime() function parses an English textual datetime into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT). Note: If the year is specified in a two-digit format, values between 0-69 are mapped to 2000-2069 and values between 70-100 are mapped to 1970-2000.
you can use date('Y-m-d h:i:s', strtotime($yourDate));
Hope it will help you :)
Ah OK...in php, that long timestamp ending with Z can be converted to a unix timestamp with strototime and then back to a date using the date function
echo date("Y-m-d H:i:s", strtotime("2017-01-10T18:00:00.000Z")) . "\n";
WARNING: the current time zone setting on your server may result in the time being adjusted
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