Moment() vs predefined Moment().endof date
moment add days
moment to string
i have a moment object called date :
( Tue Apr 09 2019 00:00:00 ...)
I want to replace it with the same day at the lase minute like this :
(Tue Apr 09 2019 23:59:59 ...)
I tried to use
var date_end = moment().endOf(date),
but it only works if i put (day, week or year) is it possible to use endOf or there is an other solution?
If you already have a moment object you can just do
date.endOf('day'). I think you're misunderstanding the documentation.
var date = moment('2019-04-09') console.log('Before endOf', date.format()) date = date.endOf('day') console.log('after endOf', date.format())
Docs, Note: By default, webpack bundles all Moment.js locales (in Moment.js 2.18.1, that's To get the current date and time, just call moment() with no parameters. Moment() vs predefined Moment() date. Ask Question Asked 3 years, 3 months ago. Active 3 years, 3 months ago. Viewed 2k times 1. I am a bit confused on how the Moment functions work (such as startOf(), weekday(), etc). My question is: how do I obtain the
You can just put the particular date in moment string and get end of day
date = moment(new Date('Tue Apr 09 2019 00:00:00')); console.log('End of day = ' + date.endOf('day').toString())
End of Time, moment().endOf(String);. Mutates the original moment by setting it to the end of a unit of time. This is the same as moment#startOf , only instead of setting to the� moment.tz() (this only works with the Moment TimeZone add on) The moment() Function . When you use the default moment constructor, it will convert the date from the provided offset to the environment’s local time. Right now my local time is -05:00. As such, if I take my -03:00 date from above, and parse it with moment, I get the following:
You could use
endOf after parsing your string date with
Or you could just set the hour, minute, seconds and milliseconds manually
let myMoment = moment('2019-04-09').endOf('day'); console.log(myMoment); let myMoment2 = moment('2019-04-09').hour(23).minute(59).second(0).milliseconds(0); console.log(myMoment2);
moment().format() - momentjs.com, It takes a string of tokens and replaces them with their corresponding values. moment().format(); // "2014-09-08T08:02:17-05:00" (ISO 8601, no fractional " Today is Sunday" moment('gibberish').format('YYYY MM DD'); // "Invalid date" As of version 2.13.0, when in UTC mode, the default format is governed by moment. The test between Moment.js vs date-fns. I conducted testing against both Moment.js, date-fns and the native date methods where available. For testing, I focused on the collection of dates rather than individual dates, as this was my primary use case and I was also interested in testing the sort speed of the different libraries.
Moment.js cheatsheet, The one-page guide to Moment.js: usage, examples, links, snippets, and more. This parses the given date using the given format. Returns a moment object. Moment.js today's date. In the first example, we get today's date with Moment.js.
momentjs, By default moment tries to parse the date as an ISO-8601 string and if that does not The way Moment uses dates and times is by wrapping the existing Date() object in a endOf('day'); // Today at 23:59 AM moment().add(1, 'days').calendar ();� moment().startOf('day') == moment().startOf('day').endOf('day') is false and I suspect it would be if you pasted it into your console. Your code doesn't work because startOf and endOf are mutators.
- unable to understand your query
- moment().endOf('day') will produce this output =>Tue Apr 09 2019 23:59:59
- @SyedMehtabHassan yeah but i want it on a specific date not today
- i have answer here below with specific date object
- i want to use endof on a specific date not the today's date
- today is not 9 April today is 15th april my answer works on 9th
- i need the endof on the variable date (moment object) not today
- @mike You just have to parse your variable value with moment first, like this:
- @mike I've updated my answer to parse your date value '2019-04-09'