...

View Full Version : Local time / GMT display from data field



rgEffects
10-18-2012, 11:57 PM
I have the CRM system that I built from scratch. One of the lines that I need to display is the time of the next appointment. It's a piece of cake to get it done for the users local time zone. I'm using this code:



date ("@ G:i T ", strtotime ($row_activeContactsRS['nxtTime']));

This is displaying like this:

Next Appointment: 10/19/12 at: @ 12:30 PDT (just the bold part)
1PDT[/B] (just the bold part)

What I want to display is :

Next Appointment: 10/19/12 at: @ 12:30 PDT / 19:30 GMT

Any ideas???

Fou-Lu
10-19-2012, 12:15 AM
Use the datetime objects. Much easy:


date_default_timezone_set('UTC');

$dt = new DateTime($row_activeContactRS['nxtTime']);
$tzUTC = new DateTimeZone('UTC');
$tzPDT = new DateTimeZone('PDT');

print $dt->format('m/d/y @ G:i T') . PHP_EOL;
$dt->setTimezone($tzUTC);
print $dt->format('m/d/y @ G:i T') . PHP_EOL;

rgEffects
10-19-2012, 12:17 PM
That's a good start. However, this just brought up a bigger problem. Users are going to be all over the world so I've got to derive their local time zone, let them enter the time as a local time zone value, store it as GMT. Storing as GMT is the only way that the local time will be correct. I'll have to find a script that will take a local time entry from a text field and convert it to GMT, then read the GMT back as local time for any user in any part of the world.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum