datetime-local 设置日期格式
的有关信息介绍如下:
datetime-local是html的对象,主要用于时间的设置,选择和处理。一般都是自己编辑方法函数来调整格式的。除了一般的date、week、month之外还有其他datetime、time之类的对象,用于实现的选择显示与处理。演示如下:
代码如下:
datatime-local:
date:
week:
month:
time:
datetime:
Click the button and set the local datetime
function myFunction(){
var x=document.getElementById("mydatetime-local").value;
year=x.substring(0,4);
month=x.substring(5,7);
day=x.substring(8,10);
hour=x.substring(11,13);
minute=x.substring(14)
format=year+"-"+day+"-"+month;
document.getElementById("demo").innerHTML = format;
}
保存为.js文件并用浏览器打开
打开后结果如下:一般不要使用firefox或者IE,使用其他浏览器,如百度浏览器。因为其他浏览器可能存在问题,显示效果比较差。
接下来设置日期,
选择年月日:
点击下拉按钮即可得到如下界面。
选择日期,这里选择2016年10月31日
选择时间,必选:
点击上下调整按钮对时间进行调整
这里调整为00:59
点击Click here 按钮:
结果显示2016-31-10
即是年-日-月格式
(yyyy-dd-mm)
此函数用于格式化时间。
function myFunction(){
var x=document.getElementById("mydatetime-local").value;
year=x.substring(0,4);
month=x.substring(5,7);
day=x.substring(8,10);
hour=x.substring(11,13);
minute=x.substring(14)
format=year+"-"+day+"-"+month;
document.getElementById("demo").innerHTML = format;
}



