PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
rossmurphy
Forum Newbie
Posts: 5 Joined: Thu Jun 11, 2009 10:33 am
Post
by rossmurphy » Fri Jul 31, 2009 4:20 pm
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);
}
jackpf
DevNet Resident
Posts: 2119 Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK
Post
by jackpf » Fri Jul 31, 2009 4:25 pm
I just tested on windows and removing (int) makes no difference at all... :/
rossmurphy
Forum Newbie
Posts: 5 Joined: Thu Jun 11, 2009 10:33 am
Post
by rossmurphy » Fri Jul 31, 2009 4:36 pm
Sorry, i mean on linux, it wouldnt work without the (int)
jackpf
DevNet Resident
Posts: 2119 Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK
Post
by jackpf » Fri Jul 31, 2009 4:51 pm
Sorry, haven't got linux on my laptop.
I'll have to test later.
redmonkey
Forum Regular
Posts: 836 Joined: Thu Dec 18, 2003 3:58 pm
Post
by redmonkey » Fri Jul 31, 2009 5:38 pm
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.
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Fri Jul 31, 2009 7:55 pm
Well, there could be a difference if one of your OSes is 64bit and the other one is 32bit.
Eran
DevNet Master
Posts: 3549 Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME
Post
by Eran » Fri Jul 31, 2009 7:56 pm
Make sure the timestamp variable itself is the same. For example, microtime() could return different results on linux vs. windows.