在前端格式化时间

This commit is contained in:
zogodo
2020-04-22 12:24:04 +08:00
parent 139f5e8263
commit e2ada515e7
3 changed files with 28 additions and 19 deletions

View File

@@ -559,6 +559,28 @@ function HttpDel(url, onsuccess, data) {
}
//Ajax-end
//DateTool-start
// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
// (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18
Date.prototype.Format = function(fmt) {
var o = {
"M+" : this.getMonth()+1, //月份
"d+" : this.getDate(), //日
"h+" : this.getHours(), //小时
"m+" : this.getMinutes(), //分
"s+" : this.getSeconds(), //秒
"q+" : Math.floor((this.getMonth()+3)/3), //季度
"S" : this.getMilliseconds() //毫秒
};
if(/(y+)/.test(fmt))
fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
for(var k in o)
if(new RegExp("("+ k +")").test(fmt))
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
return fmt;
}
//DateTool-end
var info_station_name;
var info_wifi_password;
var mqtt_addr;
@@ -593,14 +615,6 @@ HttpGet("/status", function (re) {
$("#info_mask").html(status.mask);
$("#info_gateway").html(status.gateway);
$("#uptime").html(status.up_time);
//var now = new Date()
//task_date.value = now.toLocaleDateString().replace(/\//g, '-');
//task_date.value = now.getFullYear() + '-' + now.getMonth() + '-' + now.getDate();
$("#task_date").value(status.date);
$("#task_time").value(status.time);
task_date.value = status.date;
});
//Menu-start
@@ -846,8 +860,10 @@ GetTimedTask();
var task_date = document.getElementById("task_date");
var task_time = document.getElementById("task_time");
task_date.value = "2020-12-31";
task_time.value = "10:08:00";
//task_date.value = "2020-12-31";
//task_time.value = "10:08:00";
task_date.value = (new Date()).Format("yyyy-MM-dd");
task_time.value = (new Date()).Format("hh:mm:00");
function AddTimedTask() {
var dat = task_date.value;
var tim = task_time.value;