<!DOCTYPE HTML>
<html>
<body>
<form action="/example/html5/demo_form.asp" method="get">
日期和时间:<input type="datetime-local" name="user_date" value="2015/03/27 10:41" id="user_date"/>
<input type="submit" />
</form>
</body>
</html>


或者以下这么写代码:

<html>

<title>Test_datetime_local</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>

打开后结果如下:一般不要使用firefox或者IE,使用其他浏览器,如百度浏览器。因为其他浏览器可能存在问题,显示效果比较差。

接下来设置日期,

datetime-local 设置日期格式

 这个格式适用于chrome 360 qq浏览器,但是对于firefox和ie却不适用,为此我目前还没有找到合适的办法,求指教

 

posted on 2017-03-23 16:57  忘忧❤碎  阅读(1971)  评论(0编辑  收藏  举报