News Articles momentjs

Date Difference in Years, Months, & Days in C#, ASP .NET [duplicate]

I am developing an application portal and it has a section with previous work experience. I want to find the difference between starting and ending dates of the user at a previous job. I am unable to find a method that can help me to find the difference between two dates accurately. I have tried […]

DateRangePicker material ui value formatting

I am getting the value as Fri Oct 01 2021 14:17:20 GMT+1300 (New Zealand Daylight Time) I want it to be 2021-10-01 00:00 How is it possible? Here is my code: “`const [value, setValue] = useState([null, null]); <LocalizationProvider dateAdapter={DateAdapter}> <StaticDateRangePicker displayStaticWrapperAs="desktop" allowSameDateSelection={true} format="yyyy-MM-DD HH:mm" calendars={1} value={value} onChange={(newValue) => setValue(newValue)} renderInput={(startProps, endProps) => {}} /> </LocalizationProvider>“` […]

Moment.js Internet Explorer 8 Calling moment() in console doesn’t work

page.html <html> <head> <script src="https://momentjs.com/downloads/moment.js"></script> </head> <body></body> </html> I open page.html with Internet Explorer 8.0.7601.17514, open Developer Console, enter moment().format(‘MMMM Do YYYY, h:mm:ss a’), but I get object expected. Tried window.moment().format(‘MMMM Do YYYY, h:mm:ss a’), but I get object doesn’t support this property or method. It works in Chrome. As you can see I don’t […]

Preserve Object type when using moment.format()

I’m using moment library to convert a String to Date like this: var time = moment.parseZone("2021-09-28T12:00:00-07:00"); the result is: Tue Sep 28 2021 12:00:00 GMT-0700 But if I format this: var time = moment.parseZone("2021-09-28T12:00:00-07:00").format(); This convert ‘time’ to String so I can’t manipulate it in my grid as a Date, how can I achieve this […]

Date time format in react js and moment.js in a Calendar

Basically i’m creating a calendar with events plugin and for that using react-big-calendar. I am able to create usestate to add events and show in calendar but whenever I put the start and end date with time coordinates it doesn’t show the event where when I just put the start , end date without time […]

moment().isValid returns true when the input is in integers

Code: let modifiedValue = attribute_value; let isISOFormat = moment(new Date(attribute_value), moment.ISO_8601, true).isValid(); if (isISOFormat) { modifiedValue = formatDateShortCustom(moment(attribute_value).toDate()); } return modifiedValue; }; In the code above, the attribute value can have 2021-09-29T18:30:00.000Z 080921 I want to make sure that when the attribute_value is in (1) format the code modifiedValue = formatDateShortCustom(moment(attribute_value).toDate()); should execute. However, this […]

how to compare date and time using MomentJs and React

I am using MomentJs in a ReactJs project. I am trying to compare the date and time How can I compare the time. use the remindTime object Im am currently doing the follow however does not work because it is looking at the remindTime object and not the date and time moment() >= moment(remindTime) ? […]

filtering nested arrays by date

I have an array of 273 arrays with each array containing data about a regular season NFL football game. One of the data entries in the array is the date the game takes place on. I am trying to filter my array into sub arrays containing all the games in a particular week. In other […]

Moment.js – Inconsistent date on different devices

I am facing some issues with displaying dates. when users select a date i am formatting it like this new Date(date).toISOString().split(‘T’)[0]; because this is the format our django backend expects and then the backend returns a date like this: 2021-09-02 then I am formatting the date returned from the backend with moment.js: moment.utc(new Date(date)).format(‘MMM DD’) […]

How to change Spanish language translation using moment.js in react app

I am using "moment": "^2.22.2" in react app. Other than spanish languages all the languages are working fine. Why only spanish is not working? I am using localLocale.format("DD-MMM-YYYY") format. Not using the defined formats. There is no defined format for "DD-MMM-YYYY". Please help defined formats: var localeData = moment.updateLocale(‘fr’, { longDateFormat: { LT: "h:mm", LTS: […]

Moment default timezone impacts date selected in react datepicker

I have a react-datepicker which interprets user input differently depending on the moment default timezone. The version I use of react-datepicker is above 2.0.0 meaning it doesn’t have a dependency on momentjs. I set the default timezone using the moment-timezone package with the following line in the app.tsx file: moment.tz.setDefault("UTC"); This is working throughout the […]

react-chartjs-2: Time axis with timezone using moment and custom displayFormats

I am using react-chartjs-2 with moment.js and I want to be able to display the time with a specific timezone and a specific format based on the zoom. I found this link The solution with the callback in the ticks prevent any issues with the zoom plugin. However I am not able to use the […]

Format time to new Date() format of JS

I have a time, as string "13:00:00". I need to convert it so that my date picker component gets the value in proper format because it accepts only a Date object like below: <DatePicker mode="time" locale="en_GB" // Use "en_GB" here date={new Date()} /> How to format the time string "13:00:00" or any other in the […]

How to watch vue2-date-picker

I’m trying to calculate the difference between today and given date. Here what I wrote, DATA: form: { Id: null, auditStartDate: "", auditEndDate: "", auditPassed: "", test: "", auditRemaining: "", DossierId: this.$route.params.id, }, WATCH watch: { ‘form.auditStartDate’: function (val, oldVal) { this.form.test = moment(new Date()).diff(moment(val), "days"); this.form.auditPassed = 6; console.log("here"); // this.calculatePassed(this.form.auditStartDate); }, }, DATEPICKER […]

Moment.js date/time base on diff timezone offset

I’m not sure how to spit out the right date/time using moment.js base on diff timezone offset I’ve tried USA : MA & TX console.log(moment().utcOffset(‘-5’).format(‘ddd MM/DD/y H:mm:ss’)); //MA console.log(moment().utcOffset(‘-6’).format(‘ddd MM/DD/y H:mm:ss’)); //TX I kept getting Fri 09/17/2021 18:28:21 Fri 09/17/2021 18:28:21 Source: JavaSript – Stack Overflow

Writing conditionals with moment js

Having some difficulty finding answers on how to do this. date.text("Today’s date is: " + moment().format("dddd MMM Do YY, h:mm a")); Is what I am using to display the current time on the page. I am aiming to change some css depending on the time of day. I can’t find a good example of how […]

How could I make the moment.Moment to be in UTC, but preserve the date and time?

How could I make the moment.Moment to be in UTC, but preserve the date and time? E.g. I have the moment.Moment which holds a non UTC time: Tue Sep 14 2021 00:00:00 GMT+0200 (Central European Summer Time) I want to have a moment.Moment which would have the same time, i.e. Tue Sep 14 2021 00:00:00, […]

In vue.js moment.format() returning incorrect hours

The below code in returning 5 hours ago, when i just create a record formatDate(date) { return moment(date).fromNow(); }, Source: Vue – 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.