Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP strtotime to return as UTC timestamp?

Its a bit of a sever difference problem. On my local dev. server Im using:

<?php print strtotime($date." UCT"); ?>

The above code gives me the correct timestamp for my timezone. HOWEVER, the same code returns false on the live server.

The live server has a lower version of php installed and I imagine that to be the problem.

What I'm looking for is an alternative to the above line of code.

I could use the normal strototime without the ." UCT" part and add in 2hours but would rather have PHP handle timezones.

$date looks like this: 2011-05-25 05:48:00

like image 832
CodeChap Avatar asked Jun 08 '11 07:06

CodeChap


People also ask

What does Strtotime return in PHP?

PHP strtotime() function returns a timestamp value for the given date string. Incase of failure, this function returns the boolean value false.

How do I convert Strtotime to date format?

Code for converting a string to dateTime$date = strtotime ( $input ); echo date ( 'd/M/Y h:i:s' , $date );

Why is Strtotime return false?

strtotime expects a "English textual datetime" (according to the manual), which Y-D-M is not. Any time strtotime returns false, it simply doesn't understand your string, which in this application is expected.

How do I use Strtotime?

If you want to use the PHP function strtotime to add or subtract a number of days, weeks, months or years from a date other than the current time, you can do it by passing the second optional parameter to the strtotime() function, or by adding it into the string which defines the time to parse.


Video Answer


1 Answers

<?php print strtotime($date." UTC"); ?>

instead of

<?php print strtotime($date." UCT"); ?>
like image 105
ajreal Avatar answered Sep 22 '22 06:09

ajreal