dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: JavaScript
Expertise: Beginner
Jun 2, 2008

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


Convert a Date to mm/dd/yyyy Format in JavaScript

Learn how to use a JavaScript convert date format. When you create an a Date()object in JavaScript, the value you get is something like this:


'Tue Apr 1 12:58:25 EDT 2008'

Now suppose you want to display this date in mm/dd/yyyyformat. The following code snippet provides a quick way to do this:


function formatDate(value)
{
   return value.getMonth()+1 + "/" + value.getDate() + "/" + value.getYear();
}

When this function is called with a parameter value of Tue Apr 1 12:58:25 EDT 2008, it will return the date as 4/1/2008.

Note: The getMonth() function of Date() object starts from 0 to 11, so you needs to increment it by 1to get the exact month value.

Deepak Choudhari
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date