2017-06-08 45 views
1

我想從UTC 0000小時增加或減去durationMomentjs讓我們創建一個持續時間,然後將其傳遞給add方法。他們的文檔提到在V 2.13.0中增加了混合負號和負號的支持。但是,使用一個積極的跡象是返回0的代碼可以在這個小提琴 - https://jsfiddle.net/kshitij/9jqvfk3g/Momentjs持續時間不正確地解析正號

const m = moment().utcOffset(0); 
 
m.set({hour:0,minute:0,second:0,millisecond:0}) 
 
m.utc().format('HH:mm') 
 

 
let d = moment.duration('+03:30').asHours(); 
 
console.log('Positive offset: ', d); 
 
console.log('Positive time: ', m.add(d, 'H').format()); 
 

 
let b = moment.duration('-03:30').asHours(); 
 
console.log('Negative offset: ', b); 
 
console.log('Negative time: ', m.add(b, 'H').format());
<script src="https://momentjs.com/downloads/moment.js"></script>

Momentjs duration文檔。 https://momentjs.com/docs/#/durations/

+1

我同意你的看法,'moment.duration(「+ 03:30」)'創建空持續時間('P0D'),但我不確定這是一個錯誤,也許你可以嘗試在[github](https://github.com/moment/moment/issues)上打開一個問題。 – VincenzoC

+1

我通過刪除'+'來解決它,但我有點希望這樣一個明顯的事情不能被忽略:) – Kshitij

回答