admin管理员组文章数量:1290399
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>
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.
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>
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.
Share Improve this question asked Aug 20, 2015 at 11:22 Vijikumar MVijikumar M 3,7645 gold badges34 silver badges58 bronze badges3 Answers
Reset to default 7JavaScript 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./
To format dateObject
moment(dateObject).format('MMMM Do YYYY, h:mm:ss a'); // August 20th 2015, 5:09:08 pm
you can use toLocaleDateString()
to get "dd.mm.yyy" format date
Example:var date = new Date().toLocaleDateString();
You can use a library if you really want to keep using that method of specifying the date format (using a format string, inherited from a similar C language function), but it is important to consider that that whole way of formulating dates is deprecated in js.
The remended alternative is 'Intl.DateTimeFormat' which is not a direct replacement - it does not include any way to explicitly specify a date format as a string, which is probably the idea (this allows more leeway for the system to formulate a representation suited to the user).
Also consider that you could still build a date with an explicit format by manually concatenating the ponents, but that is certainly more cumbersome and less dynamic.
本文标签: javascriptWhat is the alternate of toLocaleFormat for ChromeStack Overflow
版权声明:本文标题:javascript - What is the alternate of toLocaleFormat for Chrome? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741497799a2381912.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论