How can I format a date with momentjs without leading zeros? E.g. 2018-6-29 instead of 2018-06-29.
If the number is smaller than 10 it should not add 0 before it.
According to the docs (https://momentjs.com/docs/#/parsing/string-format/) if you use M or D instead of MM or DD in the format() function you will get the date without the 0.
moment().format("YYYY-M-DD") is what you are after.
if you also want to exclude the 0 from single digit days you can use:
moment().format("YYYY-M-D")
(fiddle here: http://jsfiddle.net/rLjQx/69671/)
You should use the format string YYYY-M-D.
Consult the documentation of how to format moments. https://momentjs.com/docs/#/displaying/format/
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