I have this code :
var dt = moment(cdt).format("L");
At some dates moment(cdt).format("L")
returns Invalid date
, So how can I return an empty string instead invalid date
.
With moment.js you can check if a date is valid with the method .isValid()
, for instance:
moment(cdt, 'L', true).isValid()
moment("12/13/2020", "DD/MM/YYYY", true).isValid()
should return False
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.