momentjs

Convert minutes to days, hours and minutes using moment js

断了今生、忘了曾经 提交于 2021-02-11 05:01:21
问题 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

Moment.js 24-hour time format, dealing with the 24th hour

家住魔仙堡 提交于 2021-02-10 12:01:39
问题 I am using momentjs to check difference in minutes between two time stamps of a train trip. The API that I'm using to grab the data from returns times in 24 hours format (momentjs: HH:mm:ss). If the trip continues to the next day, the time is shown as, for example, "24:12:00" which is pretty weird. Momentjs can't deal with this, and if I try to calculate time difference with such values I get "NaN". So I created a function to convert any "24" occurrence to "00". function maintainHour

Moment.js , Invalid date time when converting epochtime

╄→尐↘猪︶ㄣ 提交于 2021-02-08 09:30:17
问题 I have following code to convert epochtime to dateTime. var newDate = moment.unix(1525168800000).format("MM/DD/YYYY"); alert(newDate); When I check the time stamp at epochtimeconvetrer, I get back the correct time, GMT: Tuesday, May 1, 2018 10:00:00 AM But when I try to get the same value by parsing with moment, getting invalid date , 09/05/50300 http://jsfiddle.net/yLc4wops/1/ 回答1: Unix time is seconds from epoch . What you're passing is milliseconds from epoch . Divide the value by 1000,

Javascript moment - timezone, difference between dates in different time zones

一曲冷凌霜 提交于 2021-02-08 08:13:20
问题 I have: var now = moment.format(); //get current time var days = 5; //days I need to subtract from time(then) var then = '05/02/2016 12:00 am'; Now I need to get difference between now and then substract(-) 5 days but in +0000 so GMT +0. so now must be in user localtime and then must be at +0000 GMT. How I can get difference between this dates in days, hours, minutes, seconds? I try: var now = moment().format(); var then = moment('05/02/2016 12:00 am').utcOffset(+0000).format(); then = moment

Difference between dates, rounded result to nearest minute

落爺英雄遲暮 提交于 2021-02-08 06:33:13
问题 The difference between dates wants to round to the nearest minute. Round date1 , date2 down or up. The returned result is already rounded up to the full minute. I can modify date1 , date2 . Do not modify the result already returned date2- date1 Code here: https://stackblitz.com/edit/react-azau4g Example: First step this.state = { date1: "2019-06-29 21:25:38+00", date2: "2019-06-29T21:25:40.000+00:00" } round = (item) => { var m = moment(item); var roundUp = (m.second() || m.millisecond() ? m

Moment JS how to set is between and equal between 2 dates?

雨燕双飞 提交于 2021-02-07 19:50:50
问题 Hi I would like to check if given date is between 2 dates with hours of course. So if we check if 13:00 is between 13:00 and 15:00 I would like to get true. I have this code: let timeSlotStartTime = moment.utc(timeSlot.startTime); let startDayTime = moment.utc(timeSlotStartTime.format('YYYY-MM-DD') + "T" + moment.utc(condition.parameters.timeFrom).format('HH:mm:00')); let endDayTime = moment.utc(timeSlotStartTime.format('YYYY-MM-DD') + "T" + moment.utc(condition.parameters.timeTo).format('HH

Moment JS how to set is between and equal between 2 dates?

主宰稳场 提交于 2021-02-07 19:50:48
问题 Hi I would like to check if given date is between 2 dates with hours of course. So if we check if 13:00 is between 13:00 and 15:00 I would like to get true. I have this code: let timeSlotStartTime = moment.utc(timeSlot.startTime); let startDayTime = moment.utc(timeSlotStartTime.format('YYYY-MM-DD') + "T" + moment.utc(condition.parameters.timeFrom).format('HH:mm:00')); let endDayTime = moment.utc(timeSlotStartTime.format('YYYY-MM-DD') + "T" + moment.utc(condition.parameters.timeTo).format('HH

How to get a Jest custom matcher working in typescript?

旧时模样 提交于 2021-02-07 11:49:19
问题 I regularly have unit tests where I need to compare two moment objects. I'd us moment's built-in function moment.isSame(moment) to compare them. However, this means my assertion will look like this: expect(moment1.isSame(moment2)).toBeTrue(); I didn't quite like this, especially because the failure message will be less informative. Hence, I wanted to write a custom jest matcher "toBeSameMoment". The following code seems to compile at least: import moment from "moment"; declare global {

How to get a Jest custom matcher working in typescript?

烈酒焚心 提交于 2021-02-07 11:48:43
问题 I regularly have unit tests where I need to compare two moment objects. I'd us moment's built-in function moment.isSame(moment) to compare them. However, this means my assertion will look like this: expect(moment1.isSame(moment2)).toBeTrue(); I didn't quite like this, especially because the failure message will be less informative. Hence, I wanted to write a custom jest matcher "toBeSameMoment". The following code seems to compile at least: import moment from "moment"; declare global {

Javascript convert between timezones with momentjs

只谈情不闲聊 提交于 2021-02-07 08:38:52
问题 in my app the user selects a date + time, and a timezone. This choice must be shown to other users IN THEIR OWN timezone, which means if user A from New York chooses August 8, 3:00 AM in EDT, user B from Beijing will see this datetime converted to China Standard Time (CST). To do this I thought - ok I save user A's date and tell him to select out of 4 timezones. Server side I convert this from his EDT choice to UTC using moment timezone, and save it as UTC in the database, so that when I read