本文介绍了Chrome的toLocaleFormat的替代品是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to convert format of date using Javascript. I found a method called 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中工作.我想知道一个替代方法,它可以在所有浏览器上使用.请帮助我做到这一点.提前致谢.

But its working only in firefox. I want to know an alternate method for this, which will work on all the browsers. Kindly help me to do this. Thanks in advance.

推荐答案

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

JavaScript in itself doesnt have advanced parse and formatting functions for dates. Most of the time we depend on framework we are using in application or any date based plugins like this one

http://momentjs.com/

格式化dateObject

To format dateObject

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

这篇关于Chrome的toLocaleFormat的替代品是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-16 14:36