1、代码如下:<html><title>Test_datetime_local&造婷用痃lt;/title><body>datatime-local:<input type="datetime-local" id="mydatetime-local"/><br>date:<input type="date" id="mydate"/><br>week:<input type="week" id="myweek"/><br>month:<input type="month" id="mymonth"/><br>time:<input type="time" id="mytime"/><br>datetime:<input type="datetime" id="mydatetime"/><p>Click the button and set the local datetime</p><button onclick="myFunction()">Click here</button><p id="demo"></p><script>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;}</script></body></html>保存为.js文件并用浏览器打开
2、打开后结果如下:一般不要使用firefox或者IE,使用其他浏览器,如百度浏览器。因为其他浏览器可能存在问题,显示效果比较差。接下来设置日期,
3、选择年月日:点击下拉按钮即可得到如下界面。选择日期,这里选择2016年10月31日
4、选择时间,必选:点击上下调整按钮对时间进行调整这里调整为00:59
5、点击Click here 按钮:结果显示2016-31-10即是年-日-月格式(yyyy-dd-mm)
6、此函数用于格式化时间。function myFunction(){ va筠续师诈r 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;}