From the docs: “To get the current date and time, just call moment() with no parameters. This is essentially the same as calling moment(new Date()). Note: From version 2.14.0, moment([]) and moment({}) also return now. They used to default to start-of-today before 2.14.0, but that was arbitrary so it was changed.” I have tried both and also and a lot
Tag: momentjs
Adding minutes to datetime in momentjs
I need to add the variable secondsToMinutes to the startdate. secondsToMinutes is “3:20” startDate = “2:00 PM” endDate should equal “2:03:20 PM”. I’ve tried a number of ways and get errors each and every time. Date shows up as invalid date. Answer moment().format(“LTS”) returns a string value in hh:mm:ss AM/PM format. When you create a moment object using a string
Using moment to format time in relation to now
I’m trying to display a date like “a few seconds ago”, “10 minutes ago”, “a day ago” with momentjs in the browser. date returns “in 14 minutes” NOT “14 minutes ago”. How can I fix this? Answer Because you would have been comparing it in that way only. Now should be less than the date to show ago. Current Date
Get timezone from users browser using moment(timezone).js
What is the best way to get client’s timezone and convert it to some other timezone when using moment.js and moment-timezone.js I want to find out what is clients timezone and later convert his date and time into some other timezone. Does anybody has experience with this? Answer This returns the difference from the clients timezone from UTC time. You
How to compare two Moment.js Objects
I have an Array with Moment.js objects in a variable: And a function to determinate if a value is in this array: But even if i pass a moment object, as checkFeriado(moment(“2016-01-01”)); i’m getting false. Whats wrong with my code? Is there a best way to do this? Entire project have jQuery and Moment.js Answer Javascript objects cannot be compared
Deprecation warning in Moment.js – Not in a recognized ISO format
I’m getting a warning that a value provided to moment is not in a recognized ISO format. I changed my variable today with the moment function and still it doesn’t work. Here’s the warning error: Deprecation warning: value provided is not in a recognized ISO format. moment construction falls back to js Date(), which is not reliable across all browsers
Moment.js compare two date thrown a warning
I have created a simple app, which need a date comparison. I used Moment.js, and I have tried on answer on this question: Compare two dates in JS Moment js date time comparison How to compare only date in moment.js But all of them not working for me. and now I use this code: But in the console it’s thrown
How to use Moment.JS to check whether the current time is between 2 times
Say the current time is 09:34:00 (hh:mm:ss), and I have two other times in two variables: How do I use Moment.JS to check whether the current time is between beforeTime and afterTime? I’ve seen isBetween(), and I’ve tried to use it like: but that doesn’t work because as soon as I format the first (current time) moment into a string,
How to get the start time and end time in utc of a day for a specified timezone in javascript?
As the title stated, I want to get the start time and end time of a day for certain timezone and convert them to utc time. Here is my part of my implementation: The question is how to convert the time in certain timezone to utc time. Or is there any other decent solutions to it? Thank you! Edit: I
How to parse given date string using moment.js?
I want the following date string to be formatted using moment.js but it gives invalid date. How to parse it correctly or is there any other way to do so? Answer Just use pattern as second parameter in moment function more here in the docs: http://momentjs.com/docs/#/parsing/string-format/