Last Updated: March 07, 2016
·
8.305K
· cstipkovic

A simple format Date function using Javascript prototype

This is an implementation based on the Rick Strahl code:
- http://www.west-wind.com/weblog/posts/2008/Mar/18/A-simple-formatDate-function-for-JavaScript

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!

https://gist.github.com/3983879

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"

http://jsbin.com/owugiv/32/edit

3 Responses
Add your response

It works!

Example:
http://jsfiddle.net/HhPUb/2/

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 ·

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside