datetime-local 设置日期格式

 时间:2024-10-11 23:36:02

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文件并用浏览器打开

datetime-local 设置日期格式

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

datetime-local 设置日期格式

3、选择年月日:点击下拉按钮即可得到如下界面。选择日期,这里选择2016年10月31日

datetime-local 设置日期格式

4、选择时间,必选:点击上下调整按钮对时间进行调整这里调整为00:59

datetime-local 设置日期格式

5、点击Click here 按钮:结果显示2016-31-10即是年-日-月格式(yyyy-dd-mm)

datetime-local 设置日期格式

6、此函数用于格式化时间。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;}

  • 如何获取从DataPicker控件中选中的日期?
  • js 判断一个数组里有几个数值
  • js如何重置下拉框
  • 如何在myeclipse中快速找到编译后的class文件
  • js如何实现单选项选择后下面出现文字提示
  • 热门搜索
    中华文化手抄报 冬天手抄报 手抄报装饰图案 元宵节手抄报英语版 四年级手抄报图片大全 关于数学的手抄报内容 手抄报花边边框大全 热爱生命手抄报资料 健康小报手抄报 环境教育手抄报