Date object convert to moment object

Viewed 19

I am using ReactJs to create DateTime picker. Now my problem is how the date object converts to the moment object.

For example below is the date object, this object just show the value of date object:

Wed Sep 21 2022 00:17 GMT+0800 (Malaysia Time)

How can I convert to the moment object like below sample:

Moment {_isAMomentObject: true, _i: Wed Sep 21 2022 00:27:50 GMT+0800 (Malaysia Time), _isUTC: false, _pf: {…}, _locale: Locale, …}
_d
: 
Wed Sep 21 2022 00:17:50 GMT+0800 (Malaysia Time) {}
_i
: 
Wed Sep 21 2022 00:27:50 GMT+0800 (Malaysia 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, …}
[[Prototype]]
: 
Object

img1

I don't want to show the date object like the below picture:

img9

Hope someone can guide me on how to solve this problem. Is possible to solve this? Thanks.

1 Answers

Perhaps you should use the following library: moment.

Here is the link to their website, the documentation is pretty well done.

Link to the site: https://momentjs.com/

I hope it will help you, i use this librairy all the time :)

Related