Php time zone

I have a date and time stored in variables, then I have this


$date_time_selected = strtotime($target_year . '-' . $target_month . '-' . $target_day . ' ' . $target_hour . ':' . $target_minute . ':' . $target_second);

also I have this


time();

I want to compare those 2 but want to do it based on a specific time zone, how could I set the time zone for each one of those

Both of those will produce a UNIX time stamp which is always UTC 0. So the timezone of your PHP script won’t matter.

If the time values you’re using in the strtotime call are for some other particular TZ though, you’ll need to know what it is.

I created a module for joomla, and it works out fine, it does calculate the time correctly, however I want to let the users be able to insert their own time zone when they use it on their website, so they can set it based on their country / time zone, so, showld I just add or substract the time difference or is there an easier way?

Either use javascript to detect or let them choose in in their account, the way you can in this forum. I recommend the second option. I hate to reply on javascript.

I actually want to let them choose it, in the module I want to add an option so they can select the timezone and then let php calculate the difference, but I am looking for an easier way than adding or substracting the difference, well, if I happen to find an easier way I will post it here for reference

okay, it looks like this is what I was looking for, I will test it and post back


date_default_timezone_set("Europe/Helsinki");
"Europe/Helsinki:".time(); 

That is simple:

PHP: DateTime::getOffset - Manual

also:

PHP: date_default_timezone_set - Manual

I am doing that, but is giving me the same result, I dont know what I´m doing wrong, basically this is what I do


date_default_timezone_set('America/Mexico_City');
//then I call time() this way
$date_time_selected = strtotime($target_year . '-' . $target_month . '-' . $target_day . ' ' . $target_hour . ':' . $target_minute . ':' . $target_second);
$seconds_left = $date_time_selected - time();

As I understand that should give me the time difference to the target day, in seconds based on the America/Mexico_City time zone, but is giving me a completely different result