在写每日签到的时候,我居然使用的是本地时间...被项目经理笑哭了...., 如果你在写单机游戏,没有游戏服务器,但又不想使用本地时间,就可以采用下面方法. 方法总结: 1. 使用HTTP请求获取服务器时间,不能实时获取服务器时间这样高频率的 2. 使用socket可以实时获取服务器时间 3. 使用C#自带API获取sql server 标准北京时间(=.=还没有找到这个API) 第HTTP方式: 代码: using UnityEngine; using System.Collections; u
通过TCP形式来获取NTP时间.主要代码如下: [DllImport("kernel32.dll")] private static extern bool SetLocalTime(ref Systemtime time); [StructLayout(LayoutKind.Sequential)] private struct Systemtime { public short year; public short month; public short dayOfWeek; pu
项目中遇到了从服务器获取时间,现在记录一下方便以后查询: 1.后台代码:(创建一个date对象并以JSON的形式返回去) // 获取服务器时间 public String getNowServerTime() { result = new HashMap<String, Object>(); result.put("nowTime", new Date()); return SUCCESS; } 2.JS获取时间的函数:(对返回的结果做处理,去掉T,并且将-替换为/.处理浏