Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

117
Views
Can't format moment object to date and time

I'm using a react component for Date picking which returns a moment object. Also, I'm using my custom component to select time and saving the value like this for example 3:30 pm .

What I want to do is make this one moment object that I can later user and format however I want.

This is my current implementation but it's not working:

formatting the time is always returning AM

const time = moment(pickupTime.formattedTime, ['hh:mm a'])
        .locale('en')
        .format('hh:mm A');

const dateTime =
        startDay.locale('en').format('MMM Do YY') + // This is the Date which is a moment object
        ' ' +
        time;
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Because string + string = string, you cannot get an object by concatenating strings.

What you need is to convert a string to a moment object:

moment('24/12/2019 09:15:00', "DD MM YYYY hh:mm:ss");

Result:

Moment {_isAMomentObject: true, _i: '24/12/2019 09:15:00', _f: 'DD MM YYYY hh:mm:ss', _isUTC: false, _pf: {…}, …}

Check out https://momentjs.com/docs/#/parsing/string-format/

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!