我必须根据当前区域设置格式化日期的 toLocaleDateString。是否有一个函数可以根据当前语言环境以 MM/DD/YYYY 格式返回格式?我希望答案类似于“MM/DD/YYYY”或“DD/MM/YYYY”,具体取决于语言环境。const options = { day: '2-digit', month: '2-digit', year: 'numeric' }
{selectedDate.toLocaleDateString(locale, options)}根据区域设置以正确格式给我日期有没有类似的东西{selectedDate.toLocaleDateFormat(locale, options)}这将返回 DD/MM/YYYY 或 MM/DD/YYYY 或任何语言环境的格式是我的代码和框有代码https://codesandbox.io/s/musing-benz-yzvhx
2 回答
江户川乱折腾
TA贡献1851条经验 获得超5个赞
var d = new Date();
d = String(d)
var res = d.split("-");
console.log(res)
preFormat = (res[0].split(" "))
month = preFormat[1]
day = preFormat[2]
year = preFormat[3]
UsFormat = ("JanFebMarAprMayJunJulAugSepOctNovDec".indexOf(month) / 3 + 1) + '/' + day + '/' + year
UkFormat = day + '/' + ("JanFebMarAprMayJunJulAugSepOctNovDec".indexOf(month) / 3 + 1) + '/' + year
console.log(UsFormat)
console.log(UkFormat)
添加回答
举报
0/150
提交
取消
