javascriptdatemomentjsmoment-timezone

MomentJS - shifts the date by a day after format operation


To work with one component, I need a unix date, to work with another - a text display of days, months and years. Also, each of them can be changed and the second one must synchronize its date with the first one. Now I'm getting an infinite loop because the format operation always shifts the date for me by one day. Can you please tell me how can I get the correct date?? enter image description here

const formatTime = ({ date, format = DEFAULT_FORMAT }: OwnProps): string => {
  const inutc = utc(date);
  console.log('inutc', inutc)
  const formatted = inutc.format(format);
  return formatted
}


Solution

  • Okay, i fixed it by replaced utc() to moment() like this:

    const formatTime = ({ date, format = DEFAULT_FORMAT }: OwnProps): string => {
      return moment(date).format(format)
    }