Last Updated: March 07, 2016
· cstipkovic

A simple format Date function using Javascript prototype

This is an implementation based on the Rick Strahl code:

I just removed the String methods and I used regex to replace the strings.

Thanks to my friend @mariorinaldi for the help :)

Below, the link to the gist of the code!

To use the method, follow example (Javascript):

d = new Date(); console.log(d.formatDate("dd/MM/yyyy hh:mm:ss t"));

Return -> "30/10/2012 11:49:49 pm"

d = new Date(); console.log(d.formatDate("dd/MM/yyyy HH:mm:ss"));

Return -> "30/10/2012 23:50:53"

3 Responses
Add your response

It works!


Having trouble with it in IE though. That could just be a jsfiddle problem.

over 1 year ago ·

Hey @gagege :)

Tks for test this code!
About the IE problem, I'll test and back with the solution soon!

Thank you very much :)

over 1 year ago ·

Hey @gagege,

A friend of mine called Douglas Castilho, tested the code using IE7/8/9 and it worked well :)

Maybe the problem is the jsfiddler! I have problems in the JS Bin using IE too!

Tks and Best :)

over 1 year ago ·