1

how to get UTC timestamp in php.. The below doesn't returns UTC timestamp, it is displaying some other timestamp

 <?php
    date_default_timezone_set('UTC');
    echo strtotime("now");

    ?>

i think, setting default timezone as not been effective?

thuk
  • 263
  • 3
  • 7
  • 21
  • Hi, please always remember to Google first. `How to get UTC timestamp in php` takes you to [this answer](http://stackoverflow.com/a/8655551/187606) – Pekka Sep 15 '13 at 03:48
  • `time()` would return you a UTC timestamp – zerkms Sep 15 '13 at 03:48

1 Answers1

1

Try this.

<?php

 print gmdate("Y-m-d\TH:i:s\Z"); 

?>

Manual

Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
  • 2
    It would return a formatted date, not a timestamp – zerkms Sep 15 '13 at 03:49
  • 5 minutes more, to accept your answer.. – thuk Sep 15 '13 at 03:51
  • @thuk: you asked about timestamp and about to accept an answer about formatted date. That's weird – zerkms Sep 15 '13 at 03:53
  • 1
    @zerkms the timestamp return on this format is in UTC , that is what i want – thuk Sep 17 '13 at 05:06
  • @thuk: timestamp doesn't represent any timezone - it's just a number of seconds since unix epoch. And the whole phrase - "the timestamp return on this format is in UTC" - doesn't make much sense. `gmdate` is a string with formatted date, it has nothing to do with timestamp. – zerkms Sep 17 '13 at 06:15