note 68156 modified in function.strtotime by derick

From: Date: Sun, 08 Apr 2007 13:02:01 +0000
Subject: note 68156 modified in function.strtotime by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-125210@lists.php.net to get a copy of this message
Be careful if you use combined JavaScript and PHP with strtotime you have to keep in mind, that you may get different timestamps. The following code will generate the same timestaps: <?php echo strtotime("2006-07-31 02:00:00"); ?> <script type="text/javascript"> document.writeln(Date.UTC(2006, 06, 31, 0, 0, 0)); </script> First you have to notice, that the Javascript Date.UTC function starts months counting with 0, not with 1 (for january) - this is documented well. But what I did not know and took me some time to find out is that you need to modify the time in strtotime() (for me it's 2 hours more than the JavaScript time). This maybe has something to do with GMT on local server, but I have no idea, so if you should know the reason why, please let me know. [Red.: This is because javascript returns UTC] --was-- Be careful if you use combined JavaScript and PHP with strtotime you have to keep in mind, that you may get different timestamps. The following code will generate the same timestaps: <?php echo strtotime("2006-07-31 02:00:00"); ?> <script type="text/javascript"> document.writeln(Date.UTC(2006, 06, 31, 0, 0, 0)); </script> First you have to notice, that the Javascript Date.UTC function starts months counting with 0, not with 1 (for january) - this is documented well. But what I did not know and took me some time to find out is that you need to modify the time in strtotime() (for me it's 2 hours more than the JavaScript time). This maybe has something to do with GMT on local server, but I have no idea, so if you should know the reason why, please let me know. Bernhard http://php.net/manual/en/function.strtotime.php

« previous php.notes (#125210) next »