简体   繁体   中英

How to get client's timezone when system date is not set?

I have to get exact client time. Now i am using javascript date function for that the problem is when user set wrong date for client machine or not set the time, getting wrong. Is it possible to get exact time from client

You can get this by the help of a server side languages like php. Check this Get Client's Accurate date time . Here I used the following functions in php.

geoip_record_by_name();
geoip_time_zone_by_country_and_region();

No,You cannot get the correct date through javascript if the client does not set correct date.Because javascript DateTime functions are reliant on client date time.Instead you can issue an ajax call to the server which fetches you the correct date time string.

Remember get the Time from the ajax call in UTC Format,so that you can convert that UTC format to your local date time using javascript

Javascript cannot provide it to you, but there are two things in the hand:

  1. Get current time from server. This can provide you GMT.
  2. Use IP address of user to determine its country. From there, you can find out about its time-zone. Thereby the correct time can be calculated by using GMT time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM