duanlinpi0265 2012-12-19 17:01
浏览 40

总是得到正确的日期时间?

I was wondering if there is any API/way/site/link that provides the correct time?

Not the servers datetime or the clients datetime. I'm using datetime to count down on my gaming site for when it is the user's time to make a play. Users come from all over the world, so using their client time would not match if it's from the US to Europe.

Then normally I would use the servers time, but somehow it skips 1.2 hours sometimes? I would like to make sure that everbody makes a timestamp from the same source and that source is always correct!

Any ideas?

  • 写回答

2条回答 默认 最新

  • dtuqxb3884 2012-12-19 17:10
    关注

    First, you should use UTC in the client and in the server code to avoid timezone problems.

    Further I understand your problem in a way that it is not so important that the time is exactly (nanoseconds) correct, it is more important, that the time will be the SAME on server and clients.

    So you'll need a unique source for that UTC time for both client and servers. This should be definitely your server. I could suggest using your server as NTP server for the clients. But assuming your are in a web environment this sounds not practicable.

    So I would suggest to add a timestamp - UTC time - to every message from server. Clients will have to use this timestamp as reference. Additonaly could make clients update their time periodically by calling your server.

    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法