0

please tell me how can i print data and time in this format using php 2014-03-011T20:34:01Z

i tried this code

$date = new DateTime();
$date->format('Y-m-d H:i:s');

and get something like that 2014-03-11 20:13:20 close enough but not exactly 2014-03-011T20:34:01Z

John Conde
  • 217,595
  • 99
  • 455
  • 496
Anni
  • 142
  • 2
  • 16
  • possible duplicate of [How to format an UTC date to use the Z (Zulu) zone designator in php?](http://stackoverflow.com/questions/17390784/how-to-format-an-utc-date-to-use-the-z-zulu-zone-designator-in-php) – Rangad Mar 11 '14 at 14:58

2 Answers2

1

Use the c format to get close:

$date = new DateTime();
$date->format('c');
// 2014-03-11T07:55:34+00:00

Or just add the T and Z yourself. Make sure you escape them as they are valid formatting parameters:

$date = new DateTime();
$date->format('Y-m-d\TH:i:s\Z');
// 2014-03-11T07:56:07Z
John Conde
  • 217,595
  • 99
  • 455
  • 496
  • In addition to this nice answer op could also have a look at the supported formats here: http://php.net/manual/en/datetime.formats.php – cptnk Mar 11 '14 at 14:59
0

What you are looking for is this

$date = Date('Y-m-d\TH:i:s\Z');
samuel.molinski
  • 1,119
  • 10
  • 24