Module not found: Can’t resolve ‘@date-io/date-fns’

$ npm i date-fns@next @date-io/date-fns@1.x reference: https://github.com/mui-org/material-ui-pickers/issues/240 https://github.com/dmtrKovalenko/date-io/issues/33 Reference: https://material-ui-pickers.dev/getting-started/installation#peer-library Important: For material-ui-pickers v3 use v1.x version of @date-io adapters. npm i @date-io/date-fns@1.x date-fns // or npm i @date-io/moment@1.x moment // or npm i -s @date-io/luxon@1.x luxon // or npm i -s @date-io/dayjs@1.x dayjs

Time zone issue involving date fns format()

You will need to subtract the time zone offset of your local time zone from the Date instance, before you pass it to format from date-fns. For example: const dt = new Date(‘2017-12-12’); const dtDateOnly = new Date(dt.valueOf() + dt.getTimezoneOffset() * 60 * 1000); console.log(format(dtDateOnly, ‘YYYY-MM-DD’)); // Always “2017-12-12” Problem You want to handle only … Read more

Format a duration ( from seconds ) using date-fns

According to the example code in date-fns/date-fns#229 (comment), we can now use intervalToDuration to convert seconds (passed as an Interval) to a Duration, which can then simplify formatting as desired by the OP: import { intervalToDuration } from ‘date-fns’ const seconds = 10000 intervalToDuration({ start: 0, end: seconds * 1000 }) // { hours: 2, … Read more

date-fns | How do I format to UTC

You were almost there. This works for me: import { parseISO } from “date-fns”; import { format, utcToZonedTime } from “date-fns-tz”; const time = “2019-10-25T08:10:00Z”; const parsedTime = parseISO(time); console.log(parsedTime); // 2019-10-25T08:10:00.000Z const formatInTimeZone = (date, fmt, tz) => format(utcToZonedTime(date, tz), fmt, { timeZone: tz }); const formattedTime = formatInTimeZone(parsedTime, “yyyy-MM-dd kk:mm:ss xxx”, “UTC”); console.log(formattedTime); … Read more

tech