开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
forked from sarsgame/framework
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (1)
master
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
项目仓库所选许可证以仓库主分支所使用许可证为准
master
分支 (1)
master
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (1)
master
ccscripts
/
time
/
TimeHelper.ts
ccscripts
/
time
/
TimeHelper.ts
TimeHelper.ts 7.93 KB
一键复制 编辑 原始数据 按行查看 历史
cgw 提交于 2019年08月27日 19:14 +08:00 . 更新目录位置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
/**
* Time接收的时间戳都是以毫秒为单位的,服务器传过来的是秒,注意转化。
*/
export default class TimeHelper {
static s_DeltaTime = 0;// 本地时间戳与服务器时间戳的差值。
static s_CurTimeZone = null; //本地时区 UTC+? 相对UTC时间多出的时区数
static s_ServerTimeZone = 8; //服务器时区 UTC+8 相对UTC时间多出的时区数
/**
* serverTime必须精确到毫秒
* @param serverTime 登录服务器的时间戳 毫秒
* @param zoneOffset 服务器的时区 秒
*/
static sync(serverTime,zoneOffset?) {
this.s_DeltaTime = serverTime - this.localNow();
if(zoneOffset){
this.s_ServerTimeZone = zoneOffset/3600;
}
this.s_CurTimeZone = 0-new Date().getTimezoneOffset()/60;
// cc.log(" this.s_DeltaTime ",this.s_DeltaTime," s_ServerTimeZone ",this.s_ServerTimeZone," s_CurTimeZone ",this.s_CurTimeZone," zoneOffset ",zoneOffset);
}
//返回服务器时间(精确到毫秒的时间戳)
static now() {
return this.localNow() + this.s_DeltaTime;
}
//根据结束时间获得剩余时间
/**
*
* @param endTime 毫秒
*/
static leftTime(endTime){
if(endTime == 0){
return 0;
}
let dis = endTime - this.now();
return dis;
}
static startTime(startTime){
return this.now() - startTime;
}
//返回本地时间(精确到毫秒的时间戳)
static localNow() {
let now = Date.now();
// cc.log(" now =================================== "+now);
return now;
}
//是否同一天
static isOneDay(timestamp,now?){
let d:Date = this.timestamp2DateObj(timestamp);
let d2:Date;
if(!now){
now = Date.now();
}
d2 = this.timestamp2DateObj(now);
return d.getDate() == d2.getDate() //d.getFullYear() == d2.getFullYear() && d.getMonth() == d2.getMonth() &&
}
static getPastTimestamp(timestamp){
let dis = this.now() - timestamp;
return dis;
}
/**
* 获取过去了多少天
* @param timestamp 登录时的时间
*/
static getPastDayNum(timestamp){
let now = this.now();
let past = now - timestamp;
// cc.log(" now ",now," time ",timestamp);
return Math.floor(past/1000/3600/24);
}
/**
* 根据时间戳 推算 当前给定时间的时间戳。
* @param timestamp 毫秒
* @param hour
* @param munite
* @param second
*/
static getDayTime(timestamp:number,hour:number,munite:number = 0,second:number = 0){
let cDate = new Date(timestamp);
let date2 = new Date(cDate.getFullYear(),cDate.getMonth(), cDate.getDate(),hour,munite,second);
return date2.getTime();
}
/**
* 获取过去了多少分钟
* @param timestamp 登录时的时间
*/
static getPastMinutesNum(timestamp){
let now = this.now();
let past = now - timestamp;
// cc.log(" now ",now," time ",timestamp);
return Math.floor(past/1000/60);
}
/**
* 获得当地的时间
* @param timestamp 服务器传递的时间戳 毫秒
*/
static getLocalDateByTime(timestamp): Date{
let d = this.Timestamp2Date(timestamp,this.s_ServerTimeZone,this.s_CurTimeZone);
return d;
}
/**
*
* @param date
*/
static getDateString(date:Date){
let year = date.getFullYear();
let month = date.getMonth()+1;
let day = date.getDate()
// cc.log(" date ",date.toLocaleString());
// cc.log(" date ",date.toLocaleDateString());
// cc.log(" date ",date.toLocaleTimeString());
return year+"/"+month+"/"+day;
}
/**
*
* @param str "2018-12-5 06:00"
*/
static getLocalDateByString(str){
let d = this.timestamp2DateObj(str);
return this.Timestamp2Date(d.getTime(),this.s_ServerTimeZone, this.s_CurTimeZone);
}
/**
*
* @param num
*/
static timestamp2DateObj(num:number):Date{
let date:Date = new Date(num)
return date;
}
/**
* 返回以timestamp计算的, 所在目标时区的Date对象
* 默认destTimeZone为本地时区
* 注意参数 timestamp 需要必须精确到 毫秒!
* 如果timestamp 是服务器的时间戳,curTimeZzone 应该是服务器的时区。
* @param timestamp curTimeZzone 的时间戳
* @param curTimeZzone 当前的时区
* @param destTimeZone 目标时区
*/
static Timestamp2Date(timestamp,curTimeZzone, destTimeZone) {
if (!destTimeZone) {
destTimeZone = curTimeZzone;
}
//当前时区比目标时区多出的时区数
let deltaTimeZone = curTimeZzone- destTimeZone;
let deltaTime = deltaTimeZone * 3600000;
let adjustedNow = timestamp - deltaTime;
return new Date(adjustedNow);
}
//返回以Now()为时间戳计算的, 所在目标时区的Date对象
static NowDate(destTimeZone) {
return this.Timestamp2Date(this.now(),this.s_CurTimeZone, destTimeZone);
}
/**
* 判断是否可以刷新。
* @param sTime 服务器时间 毫秒
* @param time 给定刷新时间
*/
static canRefresh(sTime,hour,minute:number = 0,second: number = 0){
if(sTime == 0){
return true;
}
let sDate = new Date(sTime);
let cDate = new Date(this.now());
// cc.log(" cDate.getFullYear()",cDate.getFullYear(),cDate.getDate());
cc.log(cDate.toLocaleString());
let fiveDate = new Date(cDate.getFullYear(),cDate.getMonth(), cDate.getDate(),hour,minute,second);
cc.log(fiveDate.toLocaleString());
return sDate.getTime() < fiveDate.getTime();
}
/**
* 获取登陆天数
* @param regTime 登陆时间
* @param refreshTime 刷新时间
*/
static getLoginDayNum(regTime:number,refreshTime:number){
let t0 = this.getDayTime(regTime ,refreshTime);
let t = this.getDayTime(this.now(),refreshTime);
return Math.ceil((t-t0+1)/86400000);
}
//-------------------------------
// static test(){
// let d = new Date();
// let od = this.Timestamp2Date(d.getTime(),this.s_CurTimeZone, 9);
// cc.log(" time 1 ",od.toLocaleDateString());
// cc.log(" time 2 ",od.toLocaleString());
// cc.log(" time 3 ",od.toLocaleTimeString());
// var d=new Date(); //创建一个Date对象
// var localTime = d.getTime();
// var localOffset=d.getTimezoneOffset()*60000; //获得当地时间偏移的毫秒数
// var utc = localTime + localOffset; //utc即GMT时间
// cc.log(" localTime ",localTime," localOffset ",localOffset," utc ",utc," d.getTimezoneOffset() ",d.getTimezoneOffset());
// var offset =10; //以夏威夷时间为例,东10区
// var hawaii = utc + (3600000*offset);
// cc.log(" hawaii ",hawaii);
// var nd = new Date(hawaii);
// cc.log("Hawaii time is " , nd.toLocaleString());
// }
// //时间戳换算为总毫秒数
// static TotalMillisecond() {
// return this.now();
// }
// //时间戳换算为总秒数
// static TotalSeconds() {
// return Math.floor(this.now() / 1000);
// }
// //时间戳换算为总分钟数
// static TotalMinutes() {
// return Math.floor(this.now() / (1000 * 60));
// }
// //时间戳换算为总小时数
// static TotalHours() {
// return Math.floor(this.now() / (1000 * 60 * 60));
// }
// //时间戳换算为总天数
// static TotalDays() {
// return Math.floor(this.now() / (1000 * 60 * 60 * 24));
// }
// //时间戳换算为总月数, TODO, 要怎么算?
// static TotalMonths() {
// cc.error("暂未实现");
// }
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

游戏框架,基于cocoscreator 2.0.9
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
TypeScript
1
https://gitee.com/storecodes/ccscripts.git
git@gitee.com:storecodes/ccscripts.git
storecodes
ccscripts
framework
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /