Specifying the value output of of an HTML5 input type = date?

后端 未结 3 1426
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-03 09:47

I\'d like to add native date pickers to my application, which currently uses a legacy, home-rolled system. Date input support isn\'t widespread, yet, but if I could present

3条回答
  •  有刺的猬
    2020-12-03 10:34

    The format of the HTML date field is standard. While it is not possible to change this, you can easily convert from a date object to the format you are looking for given your user has JavaScript enabled.

    // Converts any valid Date string or Date object into the format dd-MMM-yyyy
    function dateTransform(d) {
        var s = (new Date(d)).toString().split(' ');
        return [s[2],s[1],s[3]].join('-');
    }
    

    Otherwise you will need to submit in ISO format and implement a server-side solution. Perhaps in time, this could lead to more usage of the standard date format in every locality.

提交回复
热议问题