Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the alternate of toLocaleFormat for Chrome?

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.

like image 897
Can Can Avatar asked Mar 15 '23 00:03

Can Can


1 Answers

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/

To format dateObject

moment(dateObject).format('MMMM Do YYYY, h:mm:ss a'); // August 20th 2015, 5:09:08 pm
like image 188
Rahul Jujarey Avatar answered Mar 24 '23 14:03

Rahul Jujarey