How do you get the date/time in PHP for different time zone?

joohang

Lifer
Oct 22, 2000
12,340
1
0


<< i can't find any function for this, do i have to write my own? grr... >>


It's a matter of addition/subtraction.

And you can easily fetch off the code for the HTML dropdown box from anywhere. :) Just assign the values as the GMT difference.

Edit: BTW, as you know, I'm a "M$ baboon" so I don't know if there is a built-in solution in PHP. Did you try Deja.com?
 

Czar

Lifer
Oct 9, 1999
28,510
0
0
just a simple substracting and adding

if you take notice on your profile it is always about the GMT, with +5 or -3 or something. If you take like this server which is something like -5 (no idea realy) and then you calculate from that. So if I look at it it just takes the local time and adds 5 hours to it and then you have my time.

no function or anything should be needed.


and easy to create one anyways.
 

gopunk

Lifer
Jul 7, 2001
29,239
2
0
well yea, i just don't want to have to go through the trouble of making sure that the hours and dates end up right.

okay, just checked deja... i guess there is an environmental variable "TZ" that i can set. cool :)
 

gopunk

Lifer
Jul 7, 2001
29,239
2
0


<< just a simple substracting and adding

if you take notice on your profile it is always about the GMT, with +5 or -3 or something. If you take like this server which is something like -5 (no idea realy) and then you calculate from that. So if I look at it it just takes the local time and adds 5 hours to it and then you have my time.

no function or anything should be needed.
and easy to create one anyways.
>>



it would be relatively simple, but i don't feel like doing it :p i would have to right in conditionals for the date to make sure the hours stay within 0-12 or 0-24, then make sure that the day and month and even year get changed accordingly. for example, if it were december 31, 2002, 11PM, and i added 2 hours to it, i would have to make sure that all the stuff gets bumped up as well.
 

777php

Diamond Member
Jul 17, 2001
3,498
0
0
<?php
putenv("TZ=America/Los_Angeles");
?>

This will set your current env to whatever you like.

If it is for a one time use,include it within a function and call the function whenever you need to retreive the time and date
 

joohang

Lifer
Oct 22, 2000
12,340
1
0
God bless Deja.

Good developers know how to ask for help and where to get help. :)

BTW, don't you need to do calculations any ways? Even with that TZ variable.
 

joohang

Lifer
Oct 22, 2000
12,340
1
0


<< <?php
putenv("TZ=America/Los_Angeles");
?>

This will set your current env to whatever you like.

If it is for a one time use,include it within a function and call the function whenever you need to retreive the time and date
>>


Nice.

<-- learns something new everyday