datetime-local 设置日期格式

 时间:2024-10-16 20:25:16

datetime-local是html的对象,主要用于时间的设置,选择和处理。一般都是自己编辑方法函数来调整格式的。除了一般的date、week、month之外还有其他datetime、time之类的对象,用于实现的选择显示与处理。演示如下:

datetime-local 设置日期格式

工具/原料

浏览器

文本编辑器

方法/步骤

1、代码如下:<html><title>Test_d瞢铍库祢atetime_local&造婷用痃lt;/title><body>datatime-local:<inputtype="datetime-local"id="mydatetime-local"/><br>date:<inputtype="date"id="mydate"/><br>week:<inputtype="week"id="myweek"/><br>month:<inputtype="month"id="mymonth"/><br>time:<inputtype="time"id="mytime"/><br>datetime:<inputtype="datetime"id="mydatetime"/><p>Clickthebuttonandsetthelocaldatetime</p><buttononclick="myFunction()">Clickhere</button><pid="demo"></p><script>functionmyFunction(){varx=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、点击Clickhere按钮:结果显示2016-31-10即是年-日-月格式(yyyy-dd-mm)

datetime-local 设置日期格式

6、此函数用于格式化时间。functionmyFunction(){va筠续师诈rx=document.getElementById(&q锇栀劐箨uot;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如何实现单选项选择后下面出现文字提示
热门搜索
h动漫漫画 麒麟的图片 电影少女漫画 眷恋你的温柔动漫 科技创新手抄报图片