Is there any way to change input type=“date” format?

前端 未结 15 1735
清酒与你
清酒与你 2020-11-21 04:17

I\'m working with HTML5 elements on my webpage. By default input type=\"date\" shows date as YYYY-MM-DD.

The question is, is it possible t

15条回答
  •  一个人的身影
    2020-11-21 05:04

    As said, the is not fully implemented in most browsers, so let's talk about webkit like browsers (chrome).

    Using linux, you can change it by changing the environment variable LANG, LC_TIME don't seems to work(for me at least).

    You can type locale in a terminal to see your current values. I think the same concept can be applied to IOS.

    eg: Using:

    LANG=en_US.UTF-8 /opt/google/chrome/chrome
    

    The date is showed as mm/dd/yyyy

    Using:

    LANG=pt_BR /opt/google/chrome/chrome
    

    The date is showed as dd/mm/yyyy

    You can use http://lh.2xlibre.net/locale/pt_BR/ (change pt_BR by your locale) to create you own custom locale and format your dates as you want.

    A nice more advanced reference on how change default system date is: https://ccollins.wordpress.com/2009/01/06/how-to-change-date-formats-on-ubuntu/ and https://askubuntu.com/questions/21316/how-can-i-customize-a-system-locale

    You can see you real current date format using date:

    $ date +%x
    01-06-2015
    

    But as LC_TIME and d_fmt seems to be rejected by chrome ( and I think it's a bug in webkit or chrome ), sadly it don't work. :'(

    So, unfortunately the response, is IF LANG environment variable do not solve your problem, there is no way yet.

提交回复
热议问题