Javascript Convert String to Date

by top54u.com 15 Mar, 2008
Spotlight.....

To convert the string to Date in JavaScript you can use the Date Object. JavaScript supports the following Date formats that can be used to convert the string to date:

 

  • mm-dd-yyyy

  • yyyy/mm/dd

  • mm/dd/yyyy

  • mmm dd, yyyy

  • mm dd, yyyy

 

Following examples show the conversion of string to date using JavaScript Date Object:

 

Variable with Date Format as mm-dd-yyyy:

var dateString = "03-20-2008";  // mm-dd-yyyy

 

 

Variable with Date Format as yyyy/mm/dd:

var dateString = "2008/03/20";  // yyyy/mm/dd

 

 

Variable with Date Format as mm/dd/yyyy:

var dateString = "03/20/2008";  // mm/dd/yyyy

 

 

Variable with Date Format as mmm dd, yyyy:

var dateString = "March 20, 2008";  // mmm dd, yyyy

 

 

Variable with Date Format as mm dd, yyyy:

var dateString = "Mar 20, 2008";  // mm dd, yyyy

 

 

You can use any of the above date string formats that can be passed to the javascript Date Object:

 

var myDate = new Date(dateString);

document.write("Date :" + myDate.getDate());

document.write("<br>");

document.write("Month : " + myDate.getMonth());

document.write("<br>");

document.write("Year : " + myDate.getFullYear());

 

Above Example will display that output:


Date :20
Month : 2
Year : 2008

Spotlight.....

Currently rated 4.9 by 8 people

  • Currently 4.875/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , , , , , , ,

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

8/23/2008 8:41:25 PM

OUR SPONSORS[+ advertise here]
related videos.....
recent posts.....
top54u ezines.....