Youleean
Youleean

Reputation: 120

PHP Date formatting DST

I generate a unix-timestamp in the adminpanel of my site with a modified version of the jquery datetime-picker.

This timestamp get's saved into a mySQL database and in the frontend I output it via the strftime() function.

As the site has multiple admins and everybody began to add content, I encountered an offset of 1h in the output time, due to the timezone we're in (GMT+1). Because content was already added, I couldn't edit the function which generates the date and writes it to the db, so I had to edit the output function in the frontend.

I thought it would be clever to just add (myTime+3600) as an argument of the strftime function. Everything worked fine and more content got added.

Now the problem is, that all content assigned a date in april 2013 is an hour to late because of the Daylight saving time.

I only have the timestamp to work with so I somehow need to get whether a date needs the 1h offset or not. Any ideas on how to do that without adding a timezone at the timestamp generating function?

There is a function.

Any recommendations are welcome!

Example: frontend-code:

strftime("%d. %B %Y / %H:%M Uhr",new_timestamp+3600);

For 13.March 2013 16:30 I get the correct output.

For 13. April 2013 16:30 I get 17:30

Upvotes: 0

Views: 502

Answers (1)

Dave
Dave

Reputation: 3288

set the application default timezone using this http://php.net/manual/en/function.date-default-timezone-set.php that way regardless of what timezone the client is in it should force the timestamps into your primary timezone.

You may also need to edit the datetimepicker inits to force jquery to use the server based timezone too.

Upvotes: 1

Related Questions