2021年3月17日星期三

How do I convert a Date from a database to the correct timezone in Javascript with date-fns?

I need help setting a time zone because the React code on my frontend is, for some reason, is getting GMT-5.

Example: I make a manual date insertion in the database, as on the 17th and on the frontend it shows up on the 16th at 19:00 (5 hours behind).

This is the code that I managed to implement so far:

import { format } from 'date-fns';  import { ptBR } from 'date-fns/locale';    //export const remove = (index: number, set: Function, state: Array<Date>) =>  //  set(state.filter((date: Date) => state.indexOf(date) !== index));    export const formatted = (date: Date) => format(date, "dd 'de' LLLL 'de' yyyy");  

Datepicker React component:

 const picker = {      inline: true,      ignoreChange: true,      onChange: (date: Date) => add(date, setData, data, changed),      minDate: new Date(),    };      useEffect(() => {      set('holidays', data);    }, [data]);      return (      console.log(data.getTime()),      <>        <Datepicker {...picker} />        <div className={'ListContainer'}>           <Table            data={data}            setter={(data: any) => {              changed?.();              setData(data);            }}            />        </div>      </>    );  
https://stackoverflow.com/questions/66682967/how-do-i-convert-a-date-from-a-database-to-the-correct-timezone-in-javascript-wi March 18, 2021 at 08:01AM

没有评论:

发表评论