EngineUtils.js
1.2 KB
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
/**
* Created by hoopoe8 on 2017/1/8.
*/
class EngineUtils{
static isEmptyObject(O){
for (var x in O){
return false;
}
return true;
}
static arrayToJsonString(_param){
try{
return JSON.stringify(_param);
}catch (err){
console.log("arrayToJsonString error:"+err.message);
}
return null;
}
static arrayFromJsonString(_param){
try{
return JSON.parse(_param);
}catch (err){
console.log("arrayFromJsonString error:"+err.message);
}
return null;
}
//生成时间戳后9位 保证唯一
static creatTimestamp(){
let time = new Date().getTime();
let timestamp:int = time % 1000000000;//time后9位
return timestamp;
}
//生成时间戳 string
static creatTimestampStr(){
let curTime = new Date();
let timeStr = "" + curTime.getFullYear() + "-";
timeStr += (curTime.getMonth()+1) + "-";
timeStr += curTime.getDate() + "-";
timeStr+=curTime.getHours() + "-";
timeStr+=curTime.getMinutes() + "-";
timeStr+=curTime.getSeconds();
return timeStr;
}
}
export default EngineUtils;