Lua游戏开发之时区问题
转自: https://www.cnblogs.com/meteoric_cry/p/9637040.html 目前大部分游戏都采用了Lua语言进行功能开发,在进行多语种发行的时候就会遇到时区显示的问题。以韩国版本为例,场景如下: 1、服务器处于固定的位置,比如放在首尔机房; 2、玩家所处的位置不确定,可能在韩国,或者是出差在其它国家或地区; 需求: 无论在哪个国家或地区,统一显示服务器的当前时间。在PC上查看,即便在国内测试的时候也显示韩国首尔的时间(比北京时间快1个小时)。 实现: -- 北京时间 local serverTime = 1536722753 -- 2018/09/12 11:25 function getTimeZone() local now = os.time() return os.difftime(now, os.time(os.date("!*t", now))) end -- 8 hour * 3600 seconds = 28800 seconds local timeZone = getTimeZone()/ 3600 print("timeZone : " .. timeZone) local timeInterval = os.time(os.date("!*t", serverTime)) + timeZone * 3600 + (os