News Articles momentjs

How to get endOf day toISOString() in momentjs but the milliseconds should be .000Z and not .999Z

Basically I have a date: const now = moment() console.log(now.endOf(‘day’).toISOString()) // 2021-10-25T21:59:59.999Z I would like to have it as : 2021-10-25T21:59:59.000Z As a walkaround I did console.log(`${moment().endOf(‘day’).utc().format(‘YYYY-MM-DDTHH:mm:ss’)}.000Z`) and got my desired printout, but MAYBE SOMEONE HAS a more elegant way? Thanks people! Source: Vue – Stack Overflow

How to display today’s date and time as 9 am and continue till next day?

I am doing a react project.I want to display today’s date and time as "9 am" .This has to be remained unchanged till time is 9 am on next day. In short it should look like current time and date gets updated only at 9 am everyday. Source: JavaSript – Stack Overflow

Return Moment array in JS

After parsing my dates into an array, I would like to store it in a moment UseState Array. const [yearperiod, setYearPeriod ] = React.useState([moment("2021-09-09")]) const startdate : any = (document.getElementById(‘startdate’) as HTMLInputElement); const enddate : any = (document.getElementById(‘enddate’) as HTMLInputElement); const dateStart = moment(startdate.value, "DD-MM-YYYY") const dateEnd = moment(enddate.value, "DD-MM-YYYY") const interim = dateStart.clone(); const […]

How to use moment.js in pug? Property or method "moment" is not defined on the instance but referenced during render

I am using PugJs, VueJs and MomentJs to format my date. Here is my code div {{ moment(currentEvent.date).format(‘DD MMMM YYYY’) }} I have already added the library script(src!= ASSET_PATH.js + "/vendor/moment.min.js") But when I run, I got the error: Source: Vue – Stack Overflow

Using Moment.JS to calculate difference between two dates in different formats

I’m using moment.js to calculate the difference between two dates in Qualtrics. The code below has worked really well so far. The dates use a YY-mm-dd format, and at the end, I get the difference in days. const duedate= Qualtrics.SurveyEngine.getEmbeddedData(‘duedate’); const daystodue = moment(duedate).diff(moment(new Date()), ‘days’, false); Qualtrics.SurveyEngine.setEmbeddedData(‘daystill’, daystodue ); The problem is when I […]

why IsBefore moment js gives me false when should be true

My code is this: const nowDate = moment(new Date()).format("DD/MM/YYYY"); let paraRepDate = ’01/01/2021′; let calcParaDate = ’30/06/2021′; var x = moment(calcParaDate).isBefore(nowDate) console.log(x) // false How is it possible? Source: JavaSript – Stack Overflow

How to convert 340047 into days and hours duration with Moment?

How to convert 340047 into days and hours duration with Moment.js? Source: JavaSript – Stack Overflow

make new array with javascript

Need help to make new array, when I have two array First One var start=[ "11/10/2021", "05/10/2021", "16/10/2021", "03/10/2021" ] The second var end=[ "10/10/2021", "04/10/2021", "15/10/2021", "01/10/2021" ] and i make new array with code, but error: var start= []; var end= []; var daterange =[]; var daterange = JSON.stringify(response); var textdiv=JSON.parse(daterange ); for […]

How to convert Moment.js moment to unix timestamp

I see a lot in the Moment.js documentation about getting a Moment from a Unix timestamp. However, I am trying to convert a Moment to a Unix timestamp, and I am not sure how to do that. This is how my moment looks: const myMomentObject = moment(str_time, ‘YYYY-MM-DD’); And I need to convert it to […]

Moment.Js calculate difference datetime and show result

Library moments.js included. I have a variable "lastMessage.created_at" If it today’s date to display then time in the format "h:mm a" if it was yesterday, display "Yesterday" or before that "D.M.Y", how do I do this ? Source: React – Stack Overflow

Value provided is not in a recognized RFC2822 or ISO format – Vue js

I am having a problem when using this library with vue.js https://www.npmjs.com/package/vue-moment When I try to pass date in a table, I get this warning: Deprecation warning: value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non […]

Is there an equivalent to moment timezone with a Javascript date?

I have this method below that takes in a Javascript date and then has to use Moment js to do its timezone conversion. QUESTION – Is there a way to accomplish this without moment, just using a JS Date? // ex. (someDate, ‘America/Los_Angeles’, ‘MMM DD @ h:mm A z’) transform(dateUtc: Date, timeZone: string, momentFormat: string): […]

Using an interval and calculating a dateTime countdown is killing my CPU in Google Chrome

I’m showing a date/time countdown on the screen with my Angular app. It’s a countdown from a specific date and time. Running it every second is killing my CPU with Google Chrome. It might be the moment() lib that has some effect, but not sure yet. I might try it without moment, to see if […]

How can I get Moment.js to save the time selected from a dropdown in React?

It is saving the correct date selected from a calendar but it is not saving the selected time from the dropdown. Source: JavaSript – Stack Overflow

how to get a duration in human format (1 hours, 4 minutes)

I’m using ‘moment’ library. I have a duration in minutes, and I want it to be humanized. For example: const totalMinutes = 124; console.log(moment.duration(totalMinutes, ‘minutes’).humanize()); // prints 2 hours but that’s not what I want, I want it to be: 124 => 2 hours, 4 minutes 34 => 34 minutes // no hours 725 => […]

Get relative date in auto format using Luxon

Trying a simple code here using Intl library internally on top of Luxon here to get relative dates. If my current date is in 2 hours ago, in 2 hours, etc, I want it to display today. Else, I want it to display 1 day ago or in 1 day. I have numeric set to […]

How to convert mmddyyyy date format to mm/dd/yyyy in nodejs

I have a dateformat date="11032020"(mmddyyyy) output expected:11/03/2020 I want to convert this to mm/dd/yyyy in nodejs.I am a begineer to nodejs. I saw many posts where they convert from mm-dd-yyyy to different format or related.I tried converting to ISO but that did not work out. I am not able to convert mmddyyyy to different format. […]

How to manipulate toISOString output to look like the output from moment.js [duplicate]

console.log(moment(foo).format()); gives me the output: 2021-10-11T00:00:00+02:00 console.log(new Date(foo).toISOString()); gives me the output: 2021-10-10T22:00:00.000Z What do I need to do in order to get output #2 to match output #1 that uses moment? Source: JavaSript – Stack Overflow

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.