1

I have a Date/time value as such;

2014-01-07T16:19:08Z

I wish to convert it to the format below using PHP

2015-03-21 02:12:01

I know I could use string replace twice over to remove the T and Z characters but doesn't seem right..

BENN1TH
  • 2,003
  • 2
  • 31
  • 42

3 Answers3

1

The date_format() function returns a date formatted according to the specified format.

$date=date_create("2014-01-07T16:19:08Z");
echo date_format($date,"Y-m-d H:i:s");

One more way is there

echo date('Y-m-d H:i:s',strtotime('2014-01-07T16:19:08Z'));

Update

The date_create() function returns a new DateTime object.

Reference

AkshayP
  • 2,141
  • 2
  • 18
  • 27
1
  <?php
echo date('Y-m-d H:i:s',strtotime('2014-01-07T16:19:08Z'));
?>
Niroj Adhikary
  • 1,775
  • 18
  • 30
1

use strtotime() with date()

echo date('Y-m-d H:i:s',strtotime('2014-01-07T16:19:08Z'));
Niranjan N Raju
  • 12,047
  • 4
  • 22
  • 41