moment.js isValid function not working properly

In your question you write that moment(’03:55jojojo’, ‘HH:mm’,true).isValid(); returns true. This is incorrect. Please check your jsfiddle again. From http://momentjs.com/docs/ Moment’s parser is very forgiving, and this can lead to undesired behavior. As of version 2.3.0, you may specify a boolean for the last argument to make Moment use strict parsing. Strict parsing requires that … Read more

How to convert Moment.js date to users local timezone?

You do not need to use moment-timezone for this. The main moment.js library has full functionality for working with UTC and the local time zone. var testDateUtc = moment.utc(“2015-01-30 10:00:00”); var localDate = moment(testDateUtc).local(); From there you can use any of the functions you might expect: var s = localDate.format(“YYYY-MM-DD HH:mm:ss”); var d = localDate.toDate(); … Read more

How can I humanize this complete duration in moment.js / javascript

My HumanizeDuration.js library sounds like exactly what you want: humanizeDuration(1); // “1 millisecond” humanizeDuration(3000); // “3 seconds” humanizeDuration(2012); // “2 seconds, 12 milliseconds” humanizeDuration(97320000); // “1 day, 3 hours, 2 minutes” Looks like my answer’s a bit late, but maybe it’ll help others looking at this question!

Get the days, hours and minutes in Moment.js

MomentJS can calculate all that for you without you doing any logic. First find the difference between the two moments Express it as a Duration Then display whichever component .days(), .hours() of the duration that you want. Note: You can also express the entire duration .asDays(), .asHours() etc if you want. const now = moment(“2017-01-26T14:21:22+0000”); … Read more

Same date in different time zone

Here’s how you could do what you are asking: // get a moment representing the current time var now = moment(); // create a new moment based on the original one var another = now.clone(); // change the offset of the new moment – passing true to keep the local time another.utcOffset(‘+05:30’, true); // log … Read more

Convert date to UTC using moment.js

This is found in the documentation. With a library like moment, I urge you to read the entirety of the documentation. It’s really important. Assuming the input text is entered in terms of the users’s local time: var expires = moment(date).valueOf(); If the user is instructed actually enter a UTC date/time, then: var expires = … Read more