我已经测试了这段代码:
a = '10:10'
console.log( moment( a ).subtract(1, 'h').format('HH:mm'));
但是它不起作用,输出为:
Invalid date
控制台错误:
Deprecation warning: value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are discouraged and will be removed in an upcoming major release. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info.
Arguments:
[0] _isAMomentObject: true, _isUTC: false, _useUTC: false, _l: undefined, _i: 10:10, _f: undefined, _strict: undefined, _locale: [object Object]
答案 0 :(得分:2)
无法理解您为moment
的构造函数提供的时间格式。请指定时间格式作为第二个参数,您的代码应运行。
我猜测您使用的时间格式为HH:mm
,表示24小时制的小时,以及介于:
之间的分钟。
var a = '10:10'
var b = moment( a, 'HH:mm' ).subtract(1, 'h').format('HH:mm')
console.log(b);
alert(b);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>
答案 1 :(得分:0)