gpt4 book ai didi

javascript - 将日期从任何其他格式转换为 DDMMYYYY

转载 作者:行者123 更新时间:2023-12-01 00:20:03 25 4
gpt4 key购买 nike

将日期从任何其他格式转换为 DDMMYYYY

var date = new Date("2019/12/27"),
yr = date.getFullYear(),
month = date.getMonth() < 10 ? '0' + date.getMonth() : date.getMonth(),
day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate(),
newDate = yr + '-' + month + '-' + day;

我尝试过这样的但它不接受“27/12/2019”

最佳答案

使用 Moment.js 库 http://momentjs.com/这将为您省去很多麻烦。

moment().format('DDMMMYYYY');

关于javascript - 将日期从任何其他格式转换为 DDMMYYYY,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59501703/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com