News Articles momentjs

Moment js handle zulu date time

I have problem retriving data from an api and display it in local time. API print to me zulu datetime 2021-11-12T14:30:29.000000Z I’ve tried varius soluton to transform it to Europe/Rome gtm but anyone worked, considering olso DST.. moment(d.acktime, "YYYYMMDDHHmmss").utcOffset(‘Europe/Rome’).format("HH:mm"); moment(d.acktime, "YYYYMMDDHHmmss").tz("Europe/Rome").format("HH:mm"); The data displayed is always the zulu tume coming form api.. any ideas?? Source: […]

Moment-timezone failing to parse date

I’m having some issues with moment-timezone that baffle me. The same issue exists if I use just Moment. This is a react component in a next.js project. This is my code: useEffect(() => { const test = moment.utc(‘December 01, 2021 01:00pm’, ‘MMMM DD, YYYY hh:mma’) console.log(test) }, []) And the output is: Moment {_isAMomentObject: true, […]

How to migrate moment.js to the native JS

I need to migrate moment.js to native JS (TS Angular). What is the best and easiest option to migrate these methods? moment.duration(seconds) moment.duration(seconds).hours() moment.duration(seconds).minutes() moment.isMoment(time) moment.Moment.utcOffset() moment.utc(time).format(‘HH:mm’) moment(date).subtract(time, ‘seconds’) Source: JavaSript – Stack Overflow

How can I split a Day into 2 hour intervals array using momentjs in JavaScript?

I am working with charts in Reactjs and there I have to show a day into 2 hours intervals so now I don’t know how to split a day into an array of intervals. Example Array: [1-2,2-4,4-6, … 20-22,22-24] Source: JavaSript – Stack Overflow

Calculate time difference between utc date and given date in Javascript

In Javascript, I want to calculate the difference between today’date (but adjusted to GMT0) and a given date 1970/01/01 in miliseconds. On powershell for instance this will be (([datetime]::UtcNow) – (get-date "1/1/1970")).TotalMilliseconds I tried to use moment.js like : A = moment.utc(); B = moment(‘19700101’, ‘YYYYMMDD’) console.log("A is ",A) console.log("B is ",B) console.log("A format is […]

Problem with passing data between jacascript and c# – Data format issue

i am new to c# and web development so i will state my problem right away: The structure is like this:- Test.aspx: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test.aspx.cs" Inherits="PartTimeFrontendMockup.Test" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback"/> <!– Font Awesome Icons –> <link rel="stylesheet" href="plugins/fontawesome-free/css/all.min.css"/> <!– Theme style –> <link id="stileAdminLTE" runat="server" rel="stylesheet" […]

Problem with passing data between jacascript and c# – Data format issue

i am new to c# and web development so i will state my problem right away: The structure is like this:- Test.aspx: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test.aspx.cs" Inherits="PartTimeFrontendMockup.Test" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback"/> <!– Font Awesome Icons –> <link rel="stylesheet" href="plugins/fontawesome-free/css/all.min.css"/> <!– Theme style –> <link id="stileAdminLTE" runat="server" rel="stylesheet" […]

How do i calculate average times in Typescript

I have an object which has the following entry in it: numberOfReturns: number = 0; returns_explanations: string [] = []; departure_time: string = ”; arrival_time: string = ”; So in departure_time i have the following information: … departure_time: 08:15 departure_time: 08:02 departure_time: 09:00 … I have an array of this whole object which will need […]

Compare if 2 dates are the same in javascript

var beginningTime = moment(‘1635750314812’, ‘YYYY/MM/DD’); // Today date var endTime = moment(undefined, ‘YYYY/MM/DD’) // Today date console.log(beginningTime.isSame(endTime)); //expect true <script src=”https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js”></script> I am using moment js to get if 2 date are the same using the above pattern. But now i get false instead of true. How to solve the issue? Source: JavaSript – Stack […]

Why is this block of code crashing Chrome but not Safari?

When running this code on Safari: function generateTimes(timeIncrement) { let currentTime = ‘0000’, times = []; do { times.push(currentTime); currentTime = moment(currentTime, ‘HHmm’) .add(timeIncrement, ‘minutes’) .format(‘HHmm’); } while (currentTime !== ‘0000’) return times; } generateTimes(15); You get: Array (96) = $1 0 "0000" 1 "0015" 2 "0030" 3 "0045" 4 "0100" 5 "0115" 6 "0130" […]

Unable to convert date format like 12-Oct-2021 to date in Node,js

I am trying to convert dates in the format like 12-Oct-2021, 15-Nov-2021 etc to dates in Node.JS I tried using the moments library like this: const getStartEndWeek = (stringArray) => { const d = new Date(); let year = d.getFullYear() let startWeek = stringArray[0] +’-‘+ year; let endWeek = stringArray[1] +’-‘+ year; let startWeekDate = […]

Unable to convert date format like 12-Oct-2021 to date in Node,js

I am trying to convert dates in the format like 12-Oct-2021, 15-Nov-2021 etc to dates in Node.JS I tried using the moments library like this: const getStartEndWeek = (stringArray) => { const d = new Date(); let year = d.getFullYear() let startWeek = stringArray[0] +’-‘+ year; let endWeek = stringArray[1] +’-‘+ year; let startWeekDate = […]

FireEvent.change is not working for moment object

When I tried to change DatePicker input I am getting error. Here is my components: datePicker.js const DatePicker = ({ value, onChange, name, locale }) => { const myVal = value ? value.locale(locale) : ”; return ( <TextInput value={myVal} onChange={onChange} name={name} />) }; export default DatePicker; date.js import React from ‘react’; import DatePicker from ‘./datepicker’; […]

Using moment.js to check if local time is between 2 other time zones times

Similar questions have been asked but for whatever reason I just can’t wrap my head around this. I want a user anywhere in the world to see whether a shop is open or closed on my site. The shop’s hours are 8am-8pm M-F, and 8am-7pm Sat-Sun. So basically the code needs to grab the users […]

I need a loop function to check transactions from each months to show in Chart. I’m using ReactApexChart and Momentjs

Have I to create the same function changing only the range of the month consult? enter image description here Source: React – Stack Overflow

Keep local date in UTC

So I have a front end app built with react, and a backend with .Net (c#). I have this problem of time conversion being 1 day behind. so in my frontend, the date is correct, in Local time format, and when the API(backend, c#) receives the data, it converts the date into UTC which makes […]

Keep local date in UTC

So I have a front end app built with react, and a backend with .Net (c#). I have this problem of time conversion being 1 day behind. so in my frontend, the date is correct, in Local time format, and when the API(backend, c#) receives the data, it converts the date into UTC which makes […]

Moment js add date and format fails

I would like to add days to a specific date and format the output. So i have the following addDays(date){ return moment(date).add(365, ‘d’).format("DD/MM/YYYY"); } I have tested the above with the following console.log(addDays("24/05/2021")) //this returns invalid date console.log(addDays("05/06/2021")) //returns 06/05/2022 Where am i going wrong. In the first date it returns invalid date and the […]

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.