roblox无法获得服务器响应,我如何获得Roblox的当前时间(在所有服务器上保持一致)? - roblox代码 - 源码查...

问题

In my Roblox place, I want to get a value representing the current time which is consistent across all running servers and places in my game.

I already know about the Time function, but the documentation for that function seems to indicate that it is only consistent across a single place (or perhaps only a single place instance?):

Returns returns the current place time in seconds.

There's also tick:

Returns the time in UNIX time, which is the number of seconds since the Unix epoch, January 1st, 1970.

But that has another issue:

Because some servers run in different timezones (such as servers in America and Europe), tick() will return a different time on those servers. This time will differ in several hours, as much as the time zone difference is. Due this fact, it cannot say anything about relative times between two servers (such as measuring how long it has taken since the last visit of the player).

How do I get a time value that's consistent across all servers and places in my game? (The actual time in real life would work well for this purpose.)

解决方法

The Roblox Wiki article discussing tick has recently been updated to include some additional information which answers my question:

Warning: tick() returns local time, and time zones between servers may vary. A reliable option to get the same time on every server is to call os.time().

After Googling for os.time(), I discovered that it's actually part of the standard library for the LUA language. More information about os and os.time can be found here:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值