gpt4 book ai didi

javascript - Chrome 的 toLocaleFormat 的替代品是什么?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:24:01 25 4
gpt4 key购买 nike

我正在尝试使用 Javascript 转换日期格式。我找到了一个名为 toLocaleFormat 的方法。

 <script>
var today = new Date();
var formatted_string = today.toLocaleFormat('%d/%m/%Y at %H:%M:%S %p (%Z)');
document.write(formatted_string);
</script>

但它只能在 firefox 中工作。我想知道另一种方法,它适用于所有浏览器。请帮助我做到这一点。提前致谢。

最佳答案

JavaScript 本身没有日期的高级解析和格式化功能。大多数时候我们依赖于我们在应用程序中使用的框架或任何基于日期的插件,比如这个

http://momentjs.com/

格式化日期对象

moment(dateObject).format('MMMM Do YYYY, h:mm:ss a'); // August 20th 2015, 5:09:08 pm

关于javascript - Chrome 的 toLocaleFormat 的替代品是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32116926/

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