I need to make a date string of 07-26-2012 look like 7-26-2012. Easy right
date = date.replace(/^0/, '');
But 07-05-2012 also needs to be 7-5-2012. What is the best way to do that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Try
date = date.replace( /0(\d-)/g, "$1" );Simple Test.
If you’re doing heavy date manipulation in javascript then check out date.js