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

260
Views
How to convert to date-fns?

I have following moment expression:

<DialogContent>
  {startDate ? (
    <DateTimePicker
      value={startDate}
      onChange={(value: any) =>
        setStartDate(moment(value).format())

I would like to convert to date-fns format, but it fails, it is always 1970 something, why? I converted like this:

setStartDate(getUnixTime(new Date(value)))
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can import format function from date-fns and use it:

import { format } from 'date-fns';

// Pass desired format as a second parameter
setStartDate(format(value, 'yyyy-MM-dd'));
about 4 years ago · Juan Pablo Isaza Report

0

moment(value).format() return a ISO 8601 date string, look like: 2021-11-10T10:19:09+09:00. Then, I guess the setStartDate function require a date string with ISO 8601 format.

The goal is using date-fns to create a string as the result of moment.format.

To do that, you need to create a date object. If it works with moment(value) syntax, mean value is a millisecond timestamp number (1636507295498) or a formal date string (2021-11-10). Then you can create a date object by Date constructor:

new Date(value);

Now, you can use formatISO to create the required date string:

formatISO(dateObject);

The final look will be like this:

setStartDate(formatISO(new Date(value)))
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!