.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Javascript >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Show Current - Date,Month,Year in JavaScript

Posted By:Lakhan Pal Garg       Posted Date: October 05, 2009    Points: 10    Category: Javascript    URL: http://www.dotnetspark.com  
 

This Code will return the Result in numeric form as :
for date 21/8/2009:

objDate.getDate(); will return 21.
objDate.getMonth() + 1 will return 8
objDate.getFullYear() will return 2009

var objDate=new Date(); 
var today=objDate.getDate(); 
var month=objDate.getMonth() + 1; 
var year=objDate.getFullYear(); 

Sample Code To Show Today's Detail:
var months = new Array(12); 
months[0]="January"; 
months[1]="February"; 
months[2]="March"; 
months[3]="April"; 
months[4]="May"; 
months[5]="June"; 
months[6]="July"; 
months[7]="August"; 
months[8]="September"; 
months[9]="October"; 
months[10]="November"; 
months[11]="December"; 

var days = new Array(7); 
days[0]="Sunday"; 
days[1]="Monday"; 
days[2]="Tuesday"; 
days[3]="Wednesday"; 
days[4]="Thursday"; 
days[5]="Friday"; 
days[6]="Saturday"; 
var objDate=new Date(); 
var today=objDate.getDay(); 
var date=objDate.getDate(); 
var month=objDate.getMonth();
var year=objDate.getFullYear(); 
document.write("Today is : " + days[today] + ", " + months[month] + " " + date+ ", " + year);
document.write("Current date is : " + today + " / " + month + " / " + year);

Thanks & Regards
Lakhan Pal Garg

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend