I am working in React. I am troubled with getting right time format. I am selecting a time from drop down and used moment(inputTime,HH:mm) to format time, but this is how I get. What is the reason for it? Is there any alternative way other than moment(inputTime).format("HH:mm")?
Moment {_isAMomentObject: true, _i: "Tue May 04 2021 03:53:21 GMT+0530 (India Standard Time)", _isUTC: false, _pf: {…}, _locale: Locale, …} _d: Tue May 04 2021 03:53:21 GMT+0530 (India Standard Time) {} _i: "Tue May 04 2021 03:53:21 GMT+0530 (India Standard Time)" _isAMomentObject: true _isUTC: false _isValid: true _locale: Locale {_calendar: {…}, _longDateFormat: {…}, _invalidDate: "Invalid date", _dayOfMonthOrdinalParse: /\d{1,2}(th|st|nd|rd)/, ordinal: ƒ, …} _pf: {empty: false, unusedTokens: Array(0), unusedInput: Array(0), overflow: -2, charsLeftOver: 0, …} __proto__: Object
.format("HH:mm")?.format("HH:mm")only to where you show it in the view.isBetweenattached to it. It does not display the time formatted as you parsed it (technically, if you dig deep into that_pfproperty, you could probably find it, but that's implementation detail you should not depend on). When you callformat, it takes the Date and time zone information and provides the time, formatted as desired.