广告合作
  • 今日头条

    今日头条

  • 百度一下

    百度一下,你就知道

  • 新浪网

    新浪网 - 提供新闻线索,重大新闻爆料

  • 搜狐

    搜狐

  • 豆瓣

    豆瓣

  • 百度贴吧

    百度贴吧——全球领先的中文社区

  • 首页 尚未审核订阅工具 订阅

    datetime-local 设置日期格式

    来源:网络收集  点击:  时间:2024-04-07
    【导读】:
    datetime-local是html的对象,主要用于时间的设置,选择和处理。一般都是自己编辑方法函数来调整格式的。除了一般的date、week、month之外还有其他datetime、time之类的对象,用于实现的选择显示与处理。演示如下:工具/原料more浏览器文本编辑器方法/步骤1/6分步阅读

    代码如下:

    html

    titleTest_datetime_local/title

    body

    datatime-local:input type=datetime-local id=mydatetime-local/

    brdate:input type=date id=mydate/

    brweek:input type=week id=myweek/

    brmonth:input type=month id=mymonth/

    brtime:input type=time id=mytime/

    brdatetime:input type=datetime id=mydatetime/

    pClick 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/6

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

    接下来设置日期,

    3/6

    选择年月日:

    点击下拉按钮即可得到如下界面。

    选择日期,这里选择2016年10月31日

    4/6

    选择时间,必选:

    点击上下调整按钮对时间进行调整

    这里调整为00:59

    5/6

    点击Click here 按钮:

    结果显示2016-31-10

    即是年-日-月格式

    (yyyy-dd-mm)

    6/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;

    }

    注意事项

    时间必须设置后才能点击按钮

    本文关键词:

    版权声明:

    1、本文系转载,版权归原作者所有,旨在传递信息,不代表看本站的观点和立场。

    2、本站仅提供信息发布平台,不承担相关法律责任。

    3、若侵犯您的版权或隐私,请联系本站管理员删除。

    4、文章链接:http://www.ff371.cn/art_453598.html

    ©2019-2020 http://www.ff371.cn/ 国ICP备20009186号06-03 12:43:25  耗时:0.021