Page 1 of 1
(int) windows vs linux
Posted: Fri Jul 31, 2009 4:20 pm
by rossmurphy
I am developing on a windows box and the date returned is very different to the production server(linux) when i run this function below.
It is only corrected when i remove the (int). Anyone know how to get around this? or what the problem is here?
I pass in a unix time stamp.
Thanks
Code: Select all
function getTime($timestamp) {
$temp = (int)$timestamp / 1000;
return date("g:i A", $temp);
}
Re: (int) windows vs linux
Posted: Fri Jul 31, 2009 4:25 pm
by jackpf
I just tested on windows and removing (int) makes no difference at all... :/
Re: (int) windows vs linux
Posted: Fri Jul 31, 2009 4:36 pm
by rossmurphy
Sorry, i mean on linux, it wouldnt work without the (int)
Re: (int) windows vs linux
Posted: Fri Jul 31, 2009 4:51 pm
by jackpf
Sorry, haven't got linux on my laptop.
I'll have to test later.
Re: (int) windows vs linux
Posted: Fri Jul 31, 2009 5:38 pm
by redmonkey
In theory it shouldn't make any difference as a true unix timestamp should be an integer anyway so type casting it shouldn't change it's value within PHP.
Code: Select all
vivien:/usr/local/src/php/php-5.3.0-imagefilters# /usr/local/php-5.3.0/bin/php -a
Interactive shell
php > function getTime($timestamp) {
php { $temp = (int)$timestamp / 1000;
php { return date("g:i A", $temp);
php { }
php > function getTime2($timestamp) {
php { $temp = $timestamp / 1000;
php { return date("g:i A", $temp);
php { }
php > $time = time();
php > echo getTime($time);
11:57 AM
php > echo getTime2($time);
11:57 AM
php > exit
... doesn't make any difference on my machine if it's cast or not.
Re: (int) windows vs linux
Posted: Fri Jul 31, 2009 7:55 pm
by Weirdan
Well, there could be a difference if one of your OSes is 64bit and the other one is 32bit.
Re: (int) windows vs linux
Posted: Fri Jul 31, 2009 7:56 pm
by Eran
Make sure the timestamp variable itself is the same. For example, microtime() could return different results on linux vs. windows.