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.
61 lines
2.6 KiB
JavaScript
61 lines
2.6 KiB
JavaScript
6 years ago
|
class DateUtils {
|
||
|
|
||
|
//--------------------------
|
||
|
// constructor
|
||
|
//--------------------------
|
||
|
constructor() {}
|
||
|
|
||
|
//--------------------------
|
||
|
// 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;
|
||
|
}
|
||
|
|
||
|
convertMKtime(seconds) {
|
||
|
var date = new Date(seconds * 1000);
|
||
|
return date;
|
||
|
}
|
||
|
|
||
6 years ago
|
getDate(type, rawdate) {
|
||
6 years ago
|
var day = ((rawdate != null || rawdate != '') ? String(new Date(rawdate).getUTCDate()) : String(new Date().getUTCDate()));
|
||
6 years ago
|
var month = ((rawdate != null || rawdate != '') ? String(new Date(rawdate).getUTCMonth() + 1) : String(new Date().getUTCMonth() + 1));
|
||
6 years ago
|
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()));
|
||
6 years ago
|
var offset = ((rawdate != null || rawdate != '') ? String(new Date(rawdate).getTimezoneOffset()) : String(new Date().getTimezoneOffset()));
|
||
6 years ago
|
if (day.length == 1)
|
||
|
day = String("0" + day);
|
||
|
if (month.length == 1)
|
||
|
month = String("0" + month);
|
||
6 years ago
|
offset = String(offset / 60);
|
||
|
if (offset.length == 1)
|
||
|
offset = String("0" + offset);
|
||
6 years ago
|
switch (type) {
|
||
|
case "day":
|
||
|
return day;
|
||
|
break;
|
||
|
case "month":
|
||
|
return month;
|
||
|
break;
|
||
|
case "year":
|
||
|
return year;
|
||
|
break;
|
||
|
case "stamp":
|
||
6 years ago
|
return String(year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + seconds + "." + millisecond + "-" + (offset));
|
||
6 years ago
|
break
|
||
|
default:
|
||
6 years ago
|
return String(year + "-" + month + "-" + day);
|
||
6 years ago
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//--------------------------
|
||
|
// event handlers
|
||
|
//--------------------------
|
||
|
}
|
||
|
|
||
|
export default DateUtils
|