码迷,mamicode.com
首页 > 其他好文 > 详细

datetime-local设置初始值

时间:2016-07-15 19:44:20      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:

//全局变量

var format = "";

//构造符合datetime-local格式的当前日期
function getFormat(){
format = "";
var nTime = new Date();
format += nTime.getFullYear()+"-";
format += (nTime.getMonth()+1)<10?"0"+(nTime.getMonth()+1):(nTime.getMonth()+1);
format += "-";
format += nTime.getDate()<10?"0"+(nTime.getDate()):(nTime.getDate());
format += "T";
format += nTime.getHours()<10?"0"+(nTime.getHours()):(nTime.getHours());
format += ":";
format += nTime.getMinutes()<10?"0"+(nTime.getMinutes()):(nTime.getMinutes());
format += ":00";
}

$(function(){

  document.getElementById("endtime").value = format;//赋初始值

})

p.s:datetime-local必须格式化成"yyyy-MM-ddTHH:mm:ss"的格式

datetime-local设置初始值

标签:

原文地址:http://www.cnblogs.com/zmc-change/p/5674364.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!