<input type="text" name="end_time" id="today">
function today() {//构建方法
var today = new Date();//new 出当前时间
var h = today.getFullYear();//获取年
var m = today.getMonth() + 1;//获取月
var d = today.getDate();//获取日
var H = today.getHours();//获取时
// var M = today.getMinutes();//获取分
// var S = today.getSe
// conds();//获取秒
return h + "-" + m + "-" + d + " " + H; //返回 年-月-日 时:分:秒
}
document.getElementById("today").value = today();//将获取到的 年-月-日 时:分:秒 赋给input文本输入框
var input = document.getElementById('today');
console.log(input.value)
laydate 使用方法
<input type="text" class="demo-input" placeholder="时间选择器" id="test5">
lay('#version').html('-v' + laydate.v);
// 第一个日历
laydate.render({
elem: '#test5'
, type: 'datetime'
, done: function (value, date, endDate) {
alert(value); //得到日期生成的值,如:2017-08-18
}
});
layui UI框架中也可以运用日历插件
https://www.layui.com/doc/modules/laydate.html
具体的使用,看文档,调用中使用
获取本地时间
function hello() {
function getNowFormatDate() {
var date = new Date();
var seperator1 = "年";
var seperator3 = '月';
var seperator4 = '日';
var seperator2 = ":";
var month = date.getMonth() + 1;
// 月
console.log(month);
// 日
var strDate = date.getDate();
console.log(strDate);
// 分钟
var getMinute=date.getMinutes();
console.log(getMinute);
// 秒钟.getSeconds()
var getSeconds=date.getSeconds();
console.log(getSeconds);
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
if (getMinute >= 0 && getMinute <= 9) {
getMinute = "0" + getMinute;
}
if (getSeconds >= 0 && getSeconds <= 9) {
getSeconds = "0" + getSeconds;
}
var currentdate = date.getFullYear() + seperator1
+ month + seperator3
+ strDate + seperator4 + " "
+ date.getHours() + seperator2
+ getMinute + seperator2
+ getSeconds;
// return currentdate;
console.log(currentdate)
}
var data = getNowFormatDate();
// console.log(data);
$('#banaea_div').html(data)
}
hello();
function format(){
var nowDate = new Date();
var Y = nowDate.getFullYear();
var M = nowDate.getMonth() + 1;
M = M < 10 ? '0' + M : M;// 不够两位补充0
var D = nowDate.getDate();
D = D < 10 ? '0' + D : D;
var H = nowDate.getHours();
H = H < 10 ? '0' + H : H;
var Mi = nowDate.getMinutes();
Mi = Mi < 10 ? '0' + Mi : Mi;
var S = nowDate.getSeconds();
S = S < 10 ? '0' + S : S;
return currentdates= Y + '-' + M + '-' + D + ' ' + H + ':' + Mi + ':' + S;
}
format();
console.log(currentdates)