-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimestamp.js
36 lines (24 loc) · 988 Bytes
/
timestamp.js
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
function outPut(argTime) {
var strTime = String(argTime);
var monthNames = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"];
var reg = new RegExp(/^([a-zA-Z]+)[ ](\d{2}), (\d{4})$/);
var result = strTime.match(reg);
var obj = {};
obj.unix = null;
obj.natural = null;
if (isNaN(argTime) === false) {
var tst = Number(argTime, 10);
var dt = new Date(tst * 1000);
obj.unix = tst;
obj.natural = monthNames[dt.getMonth()] + " " +
dt.getDate() + ", " + dt.getFullYear();
} else if (result !== null) {
if(monthNames.indexOf(result[1]) !== -1) {
obj.unix = new Date(result[0]).getTime()/1000;
obj.natural = result[1] + " " + result[2] + ", " + result[3];
}
}
return JSON.stringify(obj);
}
module.exports.outPut = outPut;