date-fns

Express time as CST in javascript - date-fns

不问归期 提交于 2021-02-11 12:44:56
问题 I am using date-fns to format dates If I pass a date that ends in Z, it knows that it is UTC, and I can format(date, "yyyy-MM-dd") and it will be in local computer time. If the date I want to express in local computer time is originally CST, is there something to add at the end instead of the Z, that will be understood by the format function as a CST date? Sorry if this is a bad question Edit: is there a way to do zonedTimeToUtc(myDate, 'UTC-6') in date-fns? (instead of using a time zone name

Time zone issue involving date fns format()

假装没事ソ 提交于 2021-02-06 20:18:29
问题 const dt = new Date('2017-12-12'); console.log(format(dt, 'YYYY-MM-DD')); The above code logs 2017-12-11 in the US, but 2017-12-12 in India. I followed this github thread here and tried out things but am not getting the desired results. My expectation is to print the same date irrespective of time zone Why I need this : Consider a scenario involving birthdates. If i am giving some input date, it has to be displayed as same date in all regions irrespective of their timezones. 回答1: You will

Time zone issue involving date fns format()

让人想犯罪 __ 提交于 2021-02-06 20:18:10
问题 const dt = new Date('2017-12-12'); console.log(format(dt, 'YYYY-MM-DD')); The above code logs 2017-12-11 in the US, but 2017-12-12 in India. I followed this github thread here and tried out things but am not getting the desired results. My expectation is to print the same date irrespective of time zone Why I need this : Consider a scenario involving birthdates. If i am giving some input date, it has to be displayed as same date in all regions irrespective of their timezones. 回答1: You will

Material UI DatePicker Showing Wrong Date

六眼飞鱼酱① 提交于 2021-01-29 08:47:41
问题 The displayed date in Material UI Pickers is 1 day behind the selected date: I selected 25th, the value in formik is 25th but the value displayed on the form is 24th. "@date-io/date-fns": "^1.3.13", "date-fns": "^2.9.0", import DateFnsUtils from '@date-io/date-fns'; import { MuiPickersUtilsProvider, DatePicker } from '@material-ui/pickers'; import { format, addDays } from 'date-fns'; <MuiPickersUtilsProvider utils={DateFnsUtils}> <FastField as={DatePicker} variant="inline" disableToolbar name

date-fns returns invalid date on safari

喜你入骨 提交于 2020-05-09 10:38:20
问题 I'm using date-fns to return some values as shown below: import { format, formatDistance } from "date-fns"; var date = new Date("2019-03-06 00:00:00"); console.log(format(new Date(date), "dd MMM, y")); It works fine on Chrome and returns We Mar, y But returns Invalid Date in Safari. I believe it's because the date ("2019-03-06 00:00:00") is not in ISO 8601 format. But this is the format I'm receiving from an endpoint. Is there any option to convert this to the right format and make it work on

date-fns | How do I format to UTC

泄露秘密 提交于 2020-01-05 03:44:25
问题 Problem It looks like when I use the format() function, it automatically convert the original UTC time into my timezone (UTC+8). I have been digging through their docs for hours and couldn't seem to find a way to default it to UTC time. import { parseISO, format } from "date-fns"; const time = "2019-10-25T08:10:00Z"; const parsedTime = parseISO(time); console.log(parsedTime); // 2019-10-25T08:10:00.000Z const formattedTime = format(parsedTime, "yyyy-MM-dd kk:mm:ss"); console.log(formattedTime

Webpack warning: You may need an appropriate loader to handle this file type (date-nfs)

为君一笑 提交于 2020-01-03 20:05:40
问题 I have a problem with my application. I have a website. I use date-fns to show a formatted date based on the user language. It works great, but I have updated date-fns and since then I have a warning. In my JavaScript code I use: const locale = require(`date-fns/locale/${props.match.params.lang}`) And with this, I can generate the right format like this: format(new Date(), 'D MMMM YYYY', { locale }) It works, but I dislike this warning I get when webpack is building. Can you help me to

Webpack warning: You may need an appropriate loader to handle this file type (date-nfs)

情到浓时终转凉″ 提交于 2020-01-03 20:04:18
问题 I have a problem with my application. I have a website. I use date-fns to show a formatted date based on the user language. It works great, but I have updated date-fns and since then I have a warning. In my JavaScript code I use: const locale = require(`date-fns/locale/${props.match.params.lang}`) And with this, I can generate the right format like this: format(new Date(), 'D MMMM YYYY', { locale }) It works, but I dislike this warning I get when webpack is building. Can you help me to

How to format date/time in a specific timezone with the JavaScript date-fns library

社会主义新天地 提交于 2019-12-23 15:01:06
问题 Is there a way to format/output a date in a specified timezone with the date-fns library? I can format a date easily enough: format( new Date(), 'MM/DD/YYYY' ) And I can specify a locale (from their docs): var eoLocale = require('date-fns/locale/eo') var result = format( new Date(2014, 6, 2), 'Do [de] MMMM YYYY', {locale: eoLocale} ) How can I specify a timezone? 回答1: I am afraid, that you will have to wait for the time zone support in date-fns till the version 2.0 is released. The time zone

Parse and format date in string

强颜欢笑 提交于 2019-12-12 10:24:22
问题 I'm trying out date-fns v2. I want to format a date in a string by using the toDate and format functions: import { format, toDate } from 'date-fns' format(toDate('2019-02-11T14:00:00'), 'MM/dd/yyyy') But get the following error: RangeError: Invalid time value 回答1: It seems that you are using Version 2.0 of date-fns, which is still in alpha (development) status currently. What functions are available and how they work still seems to change frequently. For example, while in version v2.0.0-alpha