简体   繁体   English

如何在未设置系统日期时获取客户的时区?

[英]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. 现在我使用javascript日期函数,问题是当用户为客户端机器设置错误的日期或没有设置时间,出错。 Is it possible to get exact time from client 是否有可能从客户那里得到准确的时间

You can get this by the help of a server side languages like php. 你可以借助像php这样的服务器端语言来获得这个。 Check this Get Client's Accurate date time . 检查此获取客户的准确日期时间 Here I used the following functions in php. 这里我在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. 不,如果客户端没有设置正确的日期,则无法通过javascript获取正确的日期。因为javascript DateTime函数依赖于客户端日期时间。相反,您可以向服务器发出ajax调用,该服务器会提取正确的日期时间字符串。

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 请记住以UTC格式从ajax调用中获取时间,以便您可以使用javascript将该UTC格式转换为本地日期时间

Javascript cannot provide it to you, but there are two things in the hand: Javascript无法提供给您,但手中有两件事:

  1. Get current time from server. 从服务器获取当前时间。 This can provide you GMT. 这可以为您提供GMT。
  2. Use IP address of user to determine its country. 使用用户的IP地址来确定其国家/地区。 From there, you can find out about its time-zone. 从那里,您可以了解它的时区。 Thereby the correct time can be calculated by using GMT time. 从而可以通过使用GMT时间来计算正确的时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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