最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Moment js format from custom format string - Stack Overflow

programmeradmin1浏览0评论

I have a string '20-08-2018' (dd-mm-yyyy). How can I format it to (YYYY-MM-DD) moment format. WhenI'm trying to format, I got an "Invalid date"

moment(value).format('YYYY-MM-DD')

I have a string '20-08-2018' (dd-mm-yyyy). How can I format it to (YYYY-MM-DD) moment format. WhenI'm trying to format, I got an "Invalid date"

moment(value).format('YYYY-MM-DD')
Share Improve this question edited Aug 8, 2018 at 13:02 mtleppay asked Aug 8, 2018 at 11:33 mtleppaymtleppay 2812 gold badges8 silver badges15 bronze badges 1
  • Possible duplicate of Format datetime to YYYY-MM-DD HH:mm:ss in moment.js – Overflowrun Commented Aug 8, 2018 at 11:35
Add a ment  | 

1 Answer 1

Reset to default 17

Your input value is ambiguous. You should specify the input format:

moment('20-08-2018', 'DD-MM-YYYY').format('YYYY-MM-DD')
发布评论

评论列表(0)

  1. 暂无评论