datetime-local设置初始值


//全局变量

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"的格式


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM