Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
75
rated 0 times [  77] [ 2]  / answers: 1 / hits: 24772  / 11 Years ago, tue, june 11, 2013, 12:00:00

I have checked this SO post: Where can I find documentation on formatting a date in JavaScript?



Also I have looked into http://home.clara.net/shotover/datetest.htm



My string is: Mon Jun 24 2013 05:30:00 GMT+0530 (India Standard Time)



And I want to convert it to dd-mm-yyyy format.



I tried using:



var dateString = 'Mon Jun 24 2013 05:30:00 GMT+0530 (India Standard Time)';
var myDate = new Date(dateString);
var final_date = myDate.getDay()+-+(myDate.getMonth()+1)+-+myDate.getFullYear();


But it gives me the result as: 1-6-2013



The getDay() value is the index of day in a week.

For Instance,
If my dateString is Thu Jun 20 2013 05:30:00 GMT+0530 (India Standard Time)

it gives output as 4-6-2013



How can I get the proper value of Day?



P.S: I tried using .toLocaleString() and creating new date object from it. But it gives the same result.


More From » date

 Answers
4

To get the day of the month use getDate():



var final_date = myDate.getDate()+-+(myDate.getMonth()+1)+-+myDate.getFullYear();

[#77695] Monday, June 10, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
zariahdiamondz

Total Points: 649
Total Questions: 109
Total Answers: 88

Location: Tajikistan
Member since Thu, Apr 14, 2022
2 Years ago
;