Question

I've an application,say the end user might be from any country but when he does some action,i want the date to be shown in a particular time zone.

I want insert this into DB so i'm doing this using date_default_timezone_set(''); with date()

Is this the right way or should i use gmdate() and add time zone.

Thanks

No correct solution

OTHER TIPS

No, don't use date_default_timezone_set() for timezone conversions. This can have unintended side-effects.

Instead, use this:

$tz = new DateTimeZone('America/Los_Angeles');

$date = new DateTime('Thu, 31 Mar 2011 02:05:59 GMT');
$date->setTimeZone($tz);
echo $date->format('l F j Y g:i:s A I')."\n";

Note, you're creating the DateTime object using UTC time and then applying the timezone. This way is much cleaner.

If you want GMT, I think you should use the right Timezone as Europe/London

  date_default_timezone_set('Europe/London');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top