You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
2.4 KiB
JavaScript
103 lines
2.4 KiB
JavaScript
6 years ago
|
class DateUtils {
|
||
6 years ago
|
//--------------------------
|
||
|
// constructor
|
||
|
//--------------------------
|
||
|
constructor() {}
|
||
6 years ago
|
|
||
6 years ago
|
//--------------------------
|
||
|
// methods
|
||
|
//--------------------------
|
||
|
getMKtime() {
|
||
|
var time =
|
||
|
new Date(
|
||
|
new Date().getFullYear(),
|
||
|
new Date().getMonth(),
|
||
|
new Date().getDate(),
|
||
|
new Date().getHours(),
|
||
|
new Date().getMinutes(),
|
||
|
new Date().getSeconds(),
|
||
|
0
|
||
|
).getTime() / 1000;
|
||
|
return time;
|
||
|
}
|
||
6 years ago
|
|
||
6 years ago
|
convertMKtime(seconds) {
|
||
|
var date = new Date(seconds * 1000);
|
||
|
return date;
|
||
|
}
|
||
6 years ago
|
|
||
6 years ago
|
getDate(type, rawdate) {
|
||
|
var day =
|
||
|
rawdate != null || rawdate != ''
|
||
|
? String(new Date(rawdate).getUTCDate())
|
||
|
: String(new Date().getUTCDate());
|
||
|
var month =
|
||
|
rawdate != null || rawdate != ''
|
||
|
? String(new Date(rawdate).getUTCMonth() + 1)
|
||
|
: String(new Date().getUTCMonth() + 1);
|
||
|
var year =
|
||
|
rawdate != null || rawdate != ''
|
||
|
? String(new Date(rawdate).getUTCFullYear())
|
||
|
: String(new Date().getUTCFullYear());
|
||
|
var hour =
|
||
|
rawdate != null || rawdate != ''
|
||
|
? String(new Date(rawdate).getUTCHours())
|
||
|
: String(new Date().getUTCHours());
|
||
|
var minute =
|
||
|
rawdate != null || rawdate != ''
|
||
|
? String(new Date(rawdate).getUTCMinutes())
|
||
|
: String(new Date().getUTCMinutes());
|
||
|
var seconds =
|
||
|
rawdate != null || rawdate != ''
|
||
|
? String(new Date(rawdate).getUTCSeconds())
|
||
|
: String(new Date().getUTCSeconds());
|
||
|
var millisecond =
|
||
|
rawdate != null || rawdate != ''
|
||
|
? String(new Date(rawdate).getUTCMilliseconds())
|
||
|
: String(new Date().getUTCMilliseconds());
|
||
|
var offset =
|
||
|
rawdate != null || rawdate != ''
|
||
|
? String(new Date(rawdate).getTimezoneOffset())
|
||
|
: String(new Date().getTimezoneOffset());
|
||
|
if (day.length == 1) day = String('0' + day);
|
||
|
if (month.length == 1) month = String('0' + month);
|
||
|
offset = String(offset / 60);
|
||
|
if (offset.length == 1) offset = String('0' + offset);
|
||
|
switch (type) {
|
||
|
case 'day':
|
||
|
return day;
|
||
6 years ago
|
|
||
6 years ago
|
case 'month':
|
||
|
return month;
|
||
|
case 'year':
|
||
|
return year;
|
||
|
case 'stamp':
|
||
|
return String(
|
||
|
year +
|
||
|
'-' +
|
||
|
month +
|
||
|
'-' +
|
||
|
day +
|
||
|
' ' +
|
||
|
hour +
|
||
|
':' +
|
||
|
minute +
|
||
|
':' +
|
||
|
seconds +
|
||
|
'.' +
|
||
|
millisecond +
|
||
|
'-' +
|
||
|
offset
|
||
|
);
|
||
|
default:
|
||
|
return String(year + '-' + month + '-' + day);
|
||
|
}
|
||
|
}
|
||
6 years ago
|
|
||
6 years ago
|
//--------------------------
|
||
|
// event handlers
|
||
|
//--------------------------
|
||
6 years ago
|
}
|
||
|
|
||
6 years ago
|
export default DateUtils;
|