How i could convert datetime 5/8/2011 12:00:00 AM (m/d/yyyy) to dd-MMM-yyyy like 08-May-2011 in javascript.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
This link is a good resource you can use for.
http://blog.stevenlevithan.com/archives/date-time-format
Alternatively, you need to get the individual part and concatenate them as needed like below.
var now = new Date(); var hour = now.getHours(); var minute = now.getMinutes(); var second = now.getSeconds(); var monthnumber = now.getMonth(); var monthday = now.getDate(); var year = now.getYear(); String myOutput = monthday + "-" + monthnumer + "-" + year;
To get the month name instead of month number, you need to define an array like below
var arrMonths = new Array ("Jan","Feb"....};
String myOutput = monthday + "-" + arrMonths[monthnumer-1] + "-" + year;
Method 2
check below link hope you got some idea
http://bytes.com/topic/javascript/answers/519332-how-convert-datetime-format-using-javascript
http://blog.stevenlevithan.com/archives/date-time-format
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0