生无可恋。我位于德国。
我从 Sheetjs 得到一个 Date 对象。在 Excel 中,我看到一个日期,例如 2020 年 3 月 5 日。我只需要一个像 2020-03-05 这样的字符串。
这个日期给了我:
console.log(maximalesBelegdatumJS);
console.log(moment(maximalesBelegdatumJS));
console.log(moment(maximalesBelegdatumJS).format('YYYY-MM-DD'));
输出是:
Wed Mar 04 2020 23:00:00 GMT+0100 (Mitteleuropäische Normalzeit)
Moment {_isAMomentObject: true, _i: Wed Mar 04 2020 23:00:00 GMT+0100 (Mitteleuropäische Normalzeit), _isUTC: true, _offset: -0, _pf: {…}, …}_isAMomentObject: true_i: Wed Mar 04 2020 23:00:00 GMT+0100 (Mitteleuropäische Normalzeit) {}_isUTC: true_offset: -0_pf: {empty: false, unusedTokens: Array(0), unusedInput: Array(0), overflow: -2, charsLeftOver: 0, …}_locale: Locale {_calendar: {…}, _longDateFormat: {…}, _invalidDate: "Invalid date", _ordinal: "%d.", _dayOfMonthOrdinalParse: /\d{1,2}\./, …}_z: Zone {name: "UTC", abbrs: Array(1), untils: Array(1), offsets: Array(1), population: 0}_d: Wed Mar 04 2020 23:00:00 GMT+0100 (Mitteleuropäische Normalzeit) {}_isValid: true__proto__: Object
2020-03-04
我尝试了很多修饰符,例如.utc()
,.local()
但我就是不明白。
我发现的一个解决方案(但我认为是 hack)是添加utcOffset
:
console.log(moment(maximalesBelegdatumJS).add(moment(maximalesBelegdatumJS).utcOffset(), "minute"));
给予
Moment
_isAMomentObject: true
_i: Wed Mar 04 2020 23:00:00 GMT+0100 (Mitteleuropäische Normalzeit) {}
_isUTC: false
_pf: {empty: false, unusedTokens: Array(0), unusedInput: Array(0), overflow: -2, charsLeftOver: 0, …}
_locale: Locale {_calendar: {…}, _longDateFormat: {…}, _invalidDate: "Invalid date", _ordinal: "%d.", _dayOfMonthOrdinalParse: /\d{1,2}\./, …}
_d: Thu Mar 05 2020 00:00:00 GMT+0100 (Mitteleuropäische Normalzeit) {}
_isValid: true
先感谢您!