(int) windows vs linux

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

Post Reply
rossmurphy
Forum Newbie
Posts: 5
Joined: Thu Jun 11, 2009 10:33 am

(int) windows vs linux

Post 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);
 }
 
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: (int) windows vs linux

Post by jackpf »

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

Re: (int) windows vs linux

Post by rossmurphy »

Sorry, i mean on linux, it wouldnt work without the (int)
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: (int) windows vs linux

Post by jackpf »

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

Re: (int) windows vs linux

Post 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.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: (int) windows vs linux

Post by Weirdan »

Well, there could be a difference if one of your OSes is 64bit and the other one is 32bit.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: (int) windows vs linux

Post by Eran »

Make sure the timestamp variable itself is the same. For example, microtime() could return different results on linux vs. windows.
Post Reply