Convert dd.mm.yyyy format to yyyy-mm-dd

后端 未结 5 1484
孤街浪徒
孤街浪徒 2020-12-16 05:24

How can I convert dd.mm.yyyy format date to yyyy-mm-dd format in JavaScript?

Here is an example:

30.01.2010
to 
2010-01-30

Meaning

5条回答
  •  轮回少年
    2020-12-16 05:51

    Datejs is a bit bloated if you only need to do this. You can use split() and concatenate the results:

    var eu_date = '30.01.2010';
    var parts = eu_date.split('.');
    var us_date = parts[2]+'-'+parts[1]+'-'+parts[0];
    

    For these kinds of conversions where no date logic is needed, it's usually smartest to just use string manipulation tools.

提交回复
热议问题