Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

7
  • Can anyone see any issue with this approach? Commented Oct 24, 2016 at 17:54
  • 1
    use moment.js instead Commented Nov 5, 2016 at 23:36
  • @TheDembinski—what issues are you expecting? Extending built-ins is generally disliked, but I can't see an issue with Date. It would be nice if each major increment would also optionally set its minor increments (as the set* methods do), so addHours optionally took minutes, seconds and milliseconds so you could do date.addHours(3, 30) to add 3 hours and 30 minutes. addYears would take years, months and days, addMonths would take months and days, addMinutes would take minutes, seconds, milliseconds, etc.
    – RobG
    Commented Mar 1, 2017 at 3:27
  • 1
    Hi @transformer I would do something like this new Date().addHours(4).addMinutes(45); You can call as many as you want, because the methods return "this" which is the current Date Object.
    – Jacobi
    Commented Dec 28, 2017 at 17:05
  • 2
    Hi @transformer, I'm not sure I understood your problem, but these are prototype function, you can use in any order you want, ex: var dt = new Date(); then dt.addMinutes(45); dt.addHours(4); or even dt.addMinutes(285); or also dt.addMinutes(45).addHours(4); all will work. If you have a question with some code example, for your problem post it here I'll be happy to help you.
    – Jacobi
    Commented Dec 29, 2017 at 14:26