thedesk/app/js/tl/date.js

70 lines
2.0 KiB
JavaScript
Raw Normal View History

2018-01-28 23:22:43 +11:00
//日付パーサー
function date(str, datetype) {
if (datetype == "relative") {
return '<time class="timeago" datetime="' + str + '"></time>';
} else {
var date = new Date(str);
if (datetype == "unix") {
var unixm = date.getTime();
return Math.floor(unixm / 1000);
}
var now = new Date();
var month = date.getMonth() + 1;
if (date.getMinutes() < 10) {
var min = "0" + date.getMinutes();
} else {
var min = date.getMinutes();
}
if (date.getSeconds() < 10) {
var sec = "0" + date.getSeconds();
} else {
var sec = date.getSeconds();
}
if (datetype == "full") {
2018-05-26 02:37:35 +10:00
var ret = date.getFullYear() + "/" + month + "/" + date.getDate() + "/ " +
2018-01-28 23:22:43 +11:00
date.getHours() + ":" + min + ":" + sec;
}
if (date.getFullYear() == now.getFullYear()) {
if (date.getMonth() == now.getMonth()) {
if (date.getDate() == now.getDate()) {
if (datetype == "medium") {
var ret = '<time class="timeago" datetime="' + str + '"></time>';
} else {
var ret = date.getHours() + ":" + min + ":" + sec;
}
} else {
2018-05-26 02:37:35 +10:00
var ret = month + "/" + date.getDate() + " " + date.getHours() + ":" +
2018-01-28 23:22:43 +11:00
min + ":" + sec;
}
} else {
2018-05-26 02:37:35 +10:00
var ret = month + "/" + date.getDate() + " " + date.getHours() + ":" + min +
2018-01-28 23:22:43 +11:00
":" + sec;
}
} else {
2018-05-26 02:37:35 +10:00
var ret = date.getFullYear() + "/" + month + "/" + date.getDate() + " " +
2018-01-28 23:22:43 +11:00
date.getHours() + ":" + min + ":" + sec;
}
if (datetype == "double") {
return '<time class="timeago" datetime="' + str + '"></time>/' + ret;
} else {
return ret;
}
}
}
//特殊フォーマット(インスタンス情報で利用)
function crat(str) {
var date = new Date(str);
format_str = 'YYYY-MM-DD hh:mm:ss';
format_str = format_str.replace(/YYYY/g, date.getFullYear());
2018-02-25 18:21:13 +11:00
format_str = format_str.replace(/MM/g, date.getMonth()+1);
2018-01-28 23:22:43 +11:00
format_str = format_str.replace(/DD/g, date.getDate());
format_str = format_str.replace(/hh/g, date.getHours());
format_str = format_str.replace(/mm/g, date.getMinutes());
format_str = format_str.replace(/ss/g, date.getSeconds());
return format_str;
}