How to get actual UTC timestamp in PHP

Hi therel

I am working on a web application I need to get current local time of application user.

Problem is that suppose I have changed my System time clock to 10 days before or 10 Days after and I am using CSS or JQuery datePicker to show date in my application.
Then datePicker(Css,JQuery) also changed date displaying on datePicker irrespective of actual current date and according to system time clock.

So How to handle this seneraio that I will get Unique exact timeStamp of that zone.?

One solution might be.
1)Get IP Address and based on that get Current UTC time of User location.(I have not tried it yet)

Do you think many end users will have done that? Seems pretty unlikely to me, unless I’m missing something. I’m not even sure how to change my system time like that. :grimacing:

Normally User do not do it.
But this is cases of crash like.User clock has been reset,
User System is going in different timezone.Suddenly they has changed it and started application and Not taking care of it.
.How can I handle it.?

Beware: changing your system clock opens a can of worms :slight_smile:

In Windows it’s as easy as clicking on the time displayed in the task bar and using the date picker

I don’t imagine many do change it unless the change from standard ↔ daylight savings doesn’t happen on the right day. Or unless they do it intentionally to purposely mislead - “but I did fill out the survey within 5 minutes” etc.

I think what to do about it depends on how critical it is to have the correct time.
As for most things, JavaScript (users clock) for their convenience
Server side (server clock) for more reliable data.

And if possible, base start - end time on GMT

use your server time only. let the client provide its timezone for display purposes.

This will fail whenever someone uses a proxy or a vpn service, or simply happens to be at an IP that does not resolve properly to the actual location - it can happen sometimes. I think the chances of IP to location process failing are greater than the possibility of someone having incorrect time set on the computer.

If this is only for a javascript date picker I wouldn’t do anything about it as this doesn’t seem to be a critical case that needs special mechanisms. Unless, for some reasons, the reliability of your date picker is really of critical importance…

…Then your only option is to grab server time and pass it to the date picker - and the date picker is no longer dependent on the local time. For tracking passing time in javascript you can use Performance.now(), which is independent from computer clock changes.

Now you are left with the last problem - how to determine the time zone of the user? You may grab it from the computer settings with javascript but again you cannot be sure if this value is correct. In your application you could provide a setting where the user selects the time zone he is in currently - this will work well provided the user does not forget to change it whenever he moves. In other words - if the user fails to set their device or your application settings to the correct time and zone then there is nothing you can do. That’s why I would just stop worrying and allow the date picker to use the local computer time.

You can of course add a line to the php.ini file or to any web page to convert that to UTC time before using it.

this hack work actually

Thanks

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