datetime - Adding hours to Javascript Date object? -


This surprises me that JavaScript's date object does not apply to any type of function.

I just want a function that can do this:

  var now = date.Nan (); Var Chauraurilator = Now Added (4); Function date.prototype.addHours (h) {// How do I apply it? }  

I just get some hints in some direction.

  • Do I need to parse the string?

  • Can I use the settime?

  • How about milliseconds?

Like this:

  New date (millisecond + 4 * 3600 * 1000 / * 4 hours in MS / *)?  

It looks really hack though - and it also works?

JavaScript has a terrible date / time API, this is the only way to do this in pure JavaScript. I would recommend - as suggested by Nusrud - if you are manipulating in a lot of time, though.

  Date.prototype.addHours = function (h) {this.setTime (this .getTime () + (h * 60 * 60 * 1000)); This return; }  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -