I have a date string like the following: 2011-02-03. I want to remove the leading zeroes in the day and month part of the string. How do I do this?
"2011-02-03".replace(/-0+/g, '-'); // => "2011-2-3"
[Update]
Per @Lucky's question, you can account for other formats that might have a leading zero as such:
"02-03".replace(/(^|-)0+/g, "$1"); // => "2-3"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With