-1

In Javascript to get the current time for the time stamp I'm using

JSON.stringify(new Date());

Which is giving me following output.

"2016-06-07T10:38:54.767Z"

In PHP how can I get this kind of output in datetime function.

I know this problem can be handled by date function of php. But what I'm looking for is exact argument to that date function so that I can get the output same as given in the question. Which is in UTC timezone. There are similar questions explaining date function but I'm not able to figure out exact arguments for my desired output.

In PHP I tried this

date_default_timezone_set('UTC');
echo date('c');

Which is giving me

2016-06-07T11:56:54+00:00

Thanks in advance.

nim118
  • 142
  • 1
  • 9
  • 1
    Note that in JavaScript the month starts with `0` while in PHP it starts with `1` for january. If you plan on comparing values you should keep that in mind. – Gerald Schneider Jun 07 '16 at 11:03

1 Answers1

1

Reading from the DateTime Class php.net documentation,

You can use $yourdate->format('c') http://php.net/manual/en/datetime.format.php

See here for date format details : http://php.net/manual/en/function.date.php

Gerald Schneider
  • 17,416
  • 9
  • 60
  • 78
Sladix
  • 712
  • 2
  • 7
  • 19