Php timezone configuration guidelines

I live in Denmark, but I'm creating a page for a friend in the USA (Washington state). Page hosted in Surftown, Denmark.

I know there is a difference of 9 hours, so I installed:

date_default_timezone_set('America/Los_Angeles');

But I don’t quite understand something about time zones / date()and strtotime(), because:

Through text entry I am trying to save a specific date and time in a database.

Suppose input $_POST[date]: '01 / 29/2015 'and $_POST[time]input: '02: 00 PM'.

Then create a stamp using:

strtotime($_POST[date].' '.$_POST[time]);

But when I try to get this out, I get the correct date - but does 9 hours add to the time? Why is this?

I think I could just remove the time zone setting for this particular task - but I would like to understand why. I set the time zone because I also need to save some timestamps based on the actual time of the user (in the state of Washington, not in Denmark).

You can help?

+4
source share
1 answer

strtotime assumes that you are passing a UTC date to convert it to the server time zone, what you can do is this:

$ date = new DateTime ($ _ POST [date]. ''. $ _ POST [time], new DateTimeZone ("UTC"));

echo $ date-> getTimestamp ();

0
source

All Articles