momentjs

Get current GMT offset from a timezone identifier

浪尽此生 提交于 2021-02-11 15:37:20
问题 How do I get the current GMT offset from a timezone identifier? Ideally, it would include the long form name too. For example: "America/Los_Angeles" //output: GMT-0700 (Pacific Daylight Time) It would be nice if it worked with ISO strings too, for example: 2020-12-21T03:57:00Z //output: GMT-0800 (Pacific Standard Time) 回答1: You can use the timeZone and timeZoneName options of the Intl.DateTimeFormat object as below to get the name of more common timezones, but lesser known ones will probably

Get current GMT offset from a timezone identifier

本秂侑毒 提交于 2021-02-11 15:36:13
问题 How do I get the current GMT offset from a timezone identifier? Ideally, it would include the long form name too. For example: "America/Los_Angeles" //output: GMT-0700 (Pacific Daylight Time) It would be nice if it worked with ISO strings too, for example: 2020-12-21T03:57:00Z //output: GMT-0800 (Pacific Standard Time) 回答1: You can use the timeZone and timeZoneName options of the Intl.DateTimeFormat object as below to get the name of more common timezones, but lesser known ones will probably

How to find difference between time in moment.js in React Native

三世轮回 提交于 2021-02-11 15:12:52
问题 How can I find difference time in React Native (I'm using moment): Like: let end = endTime; // 10:10:05 let start = startTime; // 10:10:03 moment.utc(moment(end," hh:mm:ss").diff(moment(start," hh:mm:ss"))).format("mm:ss") //expected output: 00:00:02 回答1: You would need to use moment.duration function timeRemaining (start, end) { // get unix seconds const began = moment(start).unix(); const stopped = moment(end).unix(); // find difference between unix seconds const difference = stopped -

How to find difference between time in moment.js in React Native

孤街浪徒 提交于 2021-02-11 15:11:38
问题 How can I find difference time in React Native (I'm using moment): Like: let end = endTime; // 10:10:05 let start = startTime; // 10:10:03 moment.utc(moment(end," hh:mm:ss").diff(moment(start," hh:mm:ss"))).format("mm:ss") //expected output: 00:00:02 回答1: You would need to use moment.duration function timeRemaining (start, end) { // get unix seconds const began = moment(start).unix(); const stopped = moment(end).unix(); // find difference between unix seconds const difference = stopped -

How to parse local time without a date with moment?

夙愿已清 提交于 2021-02-11 14:00:01
问题 Input 8:30 PM with the local date of May 12th 2020 while UTC date already May 13th 2020 Desired Output 2020-05-12 20:30:00 Actual Output 2020-05-13 20:30:00 Tried 3 things: result = moment('8:30 PM', 'h:mm A').format('YYYY-MM-DD HH:mm:ss'); result = moment.tz('8:30 PM', 'h:mm A', 'America/New_York').format('YYYY-MM-DD HH:mm:ss'); moment.tz.setDefault('America/New_York'); result = moment.tz('8:30 PM', 'h:mm A', 'America/New_York').format('YYYY-MM-DD HH:mm:ss'); 回答1: As user120242 says it seems

How to parse local time without a date with moment?

雨燕双飞 提交于 2021-02-11 13:57:13
问题 Input 8:30 PM with the local date of May 12th 2020 while UTC date already May 13th 2020 Desired Output 2020-05-12 20:30:00 Actual Output 2020-05-13 20:30:00 Tried 3 things: result = moment('8:30 PM', 'h:mm A').format('YYYY-MM-DD HH:mm:ss'); result = moment.tz('8:30 PM', 'h:mm A', 'America/New_York').format('YYYY-MM-DD HH:mm:ss'); moment.tz.setDefault('America/New_York'); result = moment.tz('8:30 PM', 'h:mm A', 'America/New_York').format('YYYY-MM-DD HH:mm:ss'); 回答1: As user120242 says it seems

moment.js: Deprecation warning: value provided is not in a recognized RFC2822 or ISO format [duplicate]

浪尽此生 提交于 2021-02-11 12:16:55
问题 This question already has answers here : Deprecation warning in Moment.js - Not in a recognized ISO format (9 answers) Closed 1 year ago . I am getting date as input from an external source and it is a string, const a = '08-01-2019'; And required format for me is 'MM-DD-YYYY', const outputDateFormat = 'MM-DD-YYYY'; And I am using moment.js and doing below manipulations on that date like adding a year and decreasing a day, //adding a year const a = moment(a).add(1, 'years').add(-1, 'days')

How to find the closest time to the given time using moment?

泪湿孤枕 提交于 2021-02-11 07:14:18
问题 So I have a simple code, a working code, that get's the nearest time to the given time using moment. // Current time in millis const now = +moment('10:16', 'HH:mm').format('x'); // List of times const times = ["10:00", "10:18", "23:30", "12:00"]; // Times in milliseconds const timesInMillis = times.map(t => +moment(t, "HH:mm").format("x")); function closestTime(arr, time) { return arr.reduce(function(prev, curr) { return Math.abs(curr - time) < Math.abs(prev - time) ? curr : prev; }); } const

Convert minutes to days, hours and minutes using moment js

夙愿已清 提交于 2021-02-11 05:07:43
问题 I am using moment js to convert minutes in to days, hours and minutes moment.utc().startOf('year').add({ minutes: timeInMinute }).format('D [Days and ]HH[ Hours and ]mm'); (timeInMinute is my input variable) this is work fine for hours and minutes, but when the input value is 1441 it gives, 2 Days and 00 Hours and 01 Minutes. it should really be 1 Days and 00 Hours and 01 minutes . What am I doing wrong? please help me 回答1: You can use moment.duration to calculate hours, days, minutes etc

Convert minutes to days, hours and minutes using moment js

烈酒焚心 提交于 2021-02-11 05:01:52
问题 I am using moment js to convert minutes in to days, hours and minutes moment.utc().startOf('year').add({ minutes: timeInMinute }).format('D [Days and ]HH[ Hours and ]mm'); (timeInMinute is my input variable) this is work fine for hours and minutes, but when the input value is 1441 it gives, 2 Days and 00 Hours and 01 Minutes. it should really be 1 Days and 00 Hours and 01 minutes . What am I doing wrong? please help me 回答1: You can use moment.duration to calculate hours, days, minutes etc