What is best way to implement time zone functionaltiy in PHP?

I want to implement timezone functionality in my site, so can any help me and provide the best way to implement timezone functionality by minimum efforts.
Example:
User A from India posted tender with ending date 15/06/2016 at 4:00AM not any other user B from other country want to see time according to their timezone. So please explain whole process with database fields and flow…
Thanks for helping in advance.

The easiest way you can save the transaction date in UTC timezone and for every user they can input their timezone in their profile which you save it in the database, thus you can output any transaction date in specific user’s timezone. This would work only when the user is logged in, otherwise you can just show the date in default timezone set by your application.

Another way -it’s quite easy too I think- is using javascript to convert the transaction date (which is in UTC like first one) to user’s timezone on the web browser. There is some javascript libraries to do this, I can’t recall the library name but just google it or search for it on github.

The following JavaScript function takes a UTC date/time and returns the local time equivalent as per the timezone set on the computer:

var UTCtoLocal = function(dtutc) {
return new Date(Date.UTC(dtutc.getFullYear(), dtutc.getMonth(), dtutc.getDate(), dtutc.getHours(), dtutc.getMinutes(), dtutc.getSeconds()));
}

No huge library required.

Nice one, thanks :slight_smile:
IIRC, the library is a jQuery plugin that allows us to put a DOM selector for any date/time that needs to be converted and provides some options like formatting the date/time. So, yeah it’s just for convenience, I believe the underlying code is something like you mentioned.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.