Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Convert ISO date to more readable format?

Tags:

php

datetime

Just a simple question. How do I convert a PHP ISO time (like 2010-06-23T20:47:48-04:00) to something more readable? Is there a function already built in PHP? I've looked around but I haven't seen anything to convert times. If there's not a function, is it possible?

Thank you

like image 658
Dylan Taylor Avatar asked Jun 24 '10 01:06

Dylan Taylor


People also ask

How do I convert a date to a readable format?

Date. toUTCString() - returns the date and time in the format day, dd month yyyy hh:mm:ss GMT. Date. toISOString() - returns the date and time in the format yyyy-mm-ddThh:mm:ss.

How can I change the date format in PHP?

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: ".

How do I convert datetime to ISO 8601 in PHP?

After PHP 5 you can use this: echo date("c"); form ISO 8601 formatted datetime. Note for comments: Regarding to this, both of these expressions are valid for timezone, for basic format: ±[hh]:[mm], ±[hh][mm], or ±[hh] .

How do I convert ISO to timestamp?

Use the getTime() method to convert an ISO date to a timestamp, e.g. new Date(isoStr). getTime() . The getTime method returns the number of milliseconds since the Unix Epoch and always uses UTC for time representation. Copied!


3 Answers

$format = "d M Y"; //or something else that date() accepts as a format
date_format(date_create($time), $format);
like image 130
zebediah49 Avatar answered Oct 10 '22 09:10

zebediah49


Try this:

echo date( "Y-m-d H:i:s", strtotime("2010-06-23T20:47:48-04:00") );

Format this part "Y-m-d H:i:s" using format from this documentation http://php.net/manual/en/function.date.php

like image 9
Mladen Janjetovic Avatar answered Oct 10 '22 09:10

Mladen Janjetovic


echo strftime("%b %e %Y at %l:%M %p", strtotime($ios));

will do

like image 1
Raquibul Islam Avatar answered Oct 10 '22 07:10

Raquibul Islam