0
我需要将我的时间在军用时间24小时内转换为常规12/12时间。使用moment.js将我的变量转换为12/12时间格式
nextArrivalFinal2 = ((hour > 0 ? hour + ":" + (min < 10 ? "0" : "") : "") + min + ":" + (sec < 10 ? "0" : "") + sec);
console.log("nextArrival2", typeof nextArrivalFinal2)
console.log("nextArrival2", nextArrivalFinal2)
var convertedDate = moment(new Date(nextArrivalFinal2));
console.log('converted1', convertedDate)
console.log('converted', moment(convertedDate).format("hh:mm:ss"));
nextArrivalFinal2
显示时间为HH:MM:ss
格式的字符串。但是当我把它插入到js的时候,它说这是一个invalid date
。
如果使用moment.js,你为什么要使用日期CON结构解析字符串?使用moment.js解析(并告诉它的格式)。 24小时制的格式被军事以外的许多组织和个人使用。 ;-) – RobG
'新日期(“11:22:33”)'无效。为了使日期有效,它应该包括日期,月份和年份。 – jagzviruz