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?
标签:
javascript
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
Without regex:
The naive way to do this is to split the string on
-
, then if the value at index 1 or 2 starts with a 0, replaceAll 0 with ''. Something like (I didn't test this)[Update]
Per @Lucky's question, you can account for other formats that might have a leading zero as such:
You can use the library http://www.datejs.com/ which give you a lot of formatting option if you do not want to use the substring method.