0👍
✅
The moment(String)
constructor takes either a ISO 8601 string, or an RFC2822 date time string. If neither of those standards are used, the format must be specified as the second argument of the constructor.
expiryTime
(1200
) is in the form of hmm
, but you had specified h:mm
, which would’ve required a colon between the hour and minutes for moment
to parse the date correctly. The fix is to remove the colon.
console.log(moment(1200, 'hmm').format('h:mm'))
console.log(moment(135, 'hmm').format('h:mm'))
console.log(moment(2001, 'hmm').format('h:mm'))
<script src="https://unpkg.com/moment@2.24.0/moment.js"></script>
Source:stackexchange.com