Get the different date format in JavaScript





Hi,  
This is simple code but, i got it after so much time..


var d = new Date();
// Get today date in this format  Fri Jun 29 2012 10:57:53 GMT+0530 (IST). 


var curr_date = d.getDate();
// Get the only date from today date.


var curr_month = d.getMonth();
// Get the only month from today date.


curr_month++;
// Increase month by 1. becz, u got less one. 


var curr_year = d.getFullYear();
// Get the only year from today date.


// You can get also time, second, minute like this. 
var second =d.getSeconds();
var minutes = d.getMinutes();
var hour = d.getHours();
var milliSeconds = d.getMilliseconds();
// And also join it in date. 


// Now join it in any format. 
var today = curr_year + "-" + curr_month + "-" + curr_date;
// like this return 2012-5-12


var today = curr_year + "." + curr_month + "." + curr_date;
// like this return 2012.5.12


var today =  curr_month + "/" + curr_year + "/" + curr_date;
// like this return 5/2012/12

--
Thank You
Nelson Desai

2 comments:

anjani02 said...

A useful post with relevant insights. I appreciate the time and effort put into creating this content.ba analyst course online

online it guru said...

Really useful information here. The explanation is simple enough for someone who is new to the topic.salesforce cpq training

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by NDR Group | Bloggerized by Er. Nelson Desai | Love U My Friends