As we know that JavaScript’s Date object does not have any additional or subtract function for performing calculation between two date objects.So that I have simply written a function that can do this:
Approach-1
<!DOCTYPE html>
<html>
<head>
<title>Adding hours-JavaScript</title>
</head>
<body>
<script>
Date.prototype.addHours = function (h) {
this.setTime(this.getTime() + (h * 60 * 60 * 1000));
return this;
}
//to test this function c
document.write(new Date().addHours(4));
</script>
</body>
</html>
Approach-2
<!DOCTYPE html>
<html>
<head>
<title>Adding hours-JavaScript</title>
</head>
<body>
<script>
var currentdate = new Date();
currentdate.setMinutes(currentdate.getMinutes() + 20);
alert(currentdate);
</script>
</body>
</html>
Now we can easily able Add hours to JavaScript Date object using above two function.Let take some exmaple.
- How to add 20 minutes to a current date?
var currentdate = new Date();
currentdate.setMinutes(currentdate.getMinutes() + 20);
alert(currentdate);
- Add 5 minutes to current time javascript
var currentdate = new Date();
currentdate.setMinutes(currentdate.getMinutes() + 5);
alert(currentdate);
- How to add 30 minutes to a JavaScript Date object?
var currentdate = new Date();
currentdate.setMinutes(currentdate.getMinutes() + 30);
alert(currentdate);
The post [Solved]-How to add minutes in Date Object using javascript appeared first on Software Development | Programming Tutorials.
Read More Articles
- [Simple Way]-Cascading DropDownList in Asp.Net Mvc Using Jquery Ajax
- jQuery Ajax GET Example with Parameters
- How to Pass Parameters in AJAX POST?| JQuery Ajax Post Json Example
- [Simple Way]-How to get data from database using JQuery Ajax in asp net MVC
- How to add, edit and delete rows of an HTML table with Jquery?
- Registration form with image upload in MVC using jquery Ajax
- How to make an Inline editable table in MVC using jquery?
- Insert Update Delete Using Jquery Ajax and Modal Popup in Mvc
- [Solved]-How to Upload pdf file using jquery MVC?
- Dynamically creating graphs with jQuery
- DataTable How to add Column render from JSON
- Right way to play audio in browser?
- rowNum of jqGrid with datatype json when onPaging event raised
- javascript object oriented call function inside function or call function insede var
- Why 2 Clicks needed to submit form
- jquery go to top
- CSS and JavaScript files in Laravel 5 website
- if/else to call the function, the rest of the logic is identical
- Can anybody make a copy of this jquery effect?
- how to display message in alert if total marks does not equal 0
- How to target only the index page with jQuery/javascript?
- Make Array set of HTML string
- How do I write a custom validation to ensure 2 or more elements do not have the value?
- Socket.IO and Complex JSON with Node.js, jQuery
- Play Sound When message received
- How to play with a json object in the same file where it needs to be used?
- Transform origin change delay
- How to set sleep time in jQuery?
- Using JavaScript/jQuery to display a "Loading..." popup window that persists between pages
- Javascript JSON Object replace string within object
- Submit on enter button keypress in cshtml
- How to sort datatable?
- Get first specific elements from a defined total of elements
- How to detect if i can use jquery on a browser or not
- Jquery pass variable between methods
- Make a javascript function workable
- Draggable function in datatable
- Animate content scroll in Jquery UI Slider Widget
- How to avoid event.returnvalue is deprecated in console.log window while using jquery at server side
- Jquery best way to get a parent with a class and then find a div and iterate its divs
- if(string.Contains(string)). Is that possible?
- Javascript - Combining Multiple Function Calls / Events
- Posting two input arrays via jquery at the same time
- I want to remove the <hr> tag from the last <li> tag
- How to make link clickable or unclickable base on text in textarea?
- what is this jQuery syntax and how is it useful?
- Showing Loading Animation While Page Is Loading
- A single global variable that is always a random number each time it's referenced
- jQuery Click event is not looping. It's working only first fire
- Mobiscroll, identify element triggering it
- Most common way to structure similar but unique ajax requests that depend on Django pk?
- Jquery Datatables TypeError undefined error
- Giving td bgcolor depends on a condition
- Get values of Input[type=(type)] from specific class with jQuery
- Function does not work in Javascript
- ASP.NET MVC - Prevent Double Form Posting
- How to insert after a specific element but before another element
- jQuery - set .html() to element by it's data-for attribute
- show a div if all multiple options are selected
- Reading data from delimted string to create a select element
- function setInterval next() with active/remove class
- How to show a DIV when users reach X pixels from the bottom of the page
- creating well formed XML from not well formed XML
- Find parent of a href attribute and access specific property using jquery
- jquery - function restart
- pass href text to modal
- Populate table data with total days of month using jquery
- jquery callback variable returns "undefined"
- Google maps inside an hidden divs
- Pure CSS/JQuery Solution to center/crop different sized images in a set sized div box
- jQuery loop with wildcard
- How to find and replace date and time in textarea and convert to persian calender in javascript?
- How to avoid min value 0 in input type?
- Big problems with my current schema/syntax and coding
- why the ready() displays the image before finishing its execution?
- Moving div based on screen size
- Displaying the "IE7" version of a site on Mobile Safari
- return json from php and handle
- Twitter Bootstrap: Prevent Body from scrolling when a modal is opened
- for loop inside another for loop javascript (jquery)
- Javascript events - inline vs .on(..), how many handlers it creates?
- Datatables.net json data load
- How to get value of each array element in JSON?
- Why does on click if checked malfunction after dealing with 2nd+ index in array
- Onclick class function is not working
- Read php generated XML file with ajax & output to html using javascript
- How can we reuse jQuery ajax method for 3 functions?
- want to insert multiple values on select
- Regex with jquery
- trying to find if title contains word then hide that parent element
- How do I pass function as a parameter in javascript
- Previous next button inside bootstrap dynamic modal
- Repeated section of JavaScript - how to consolidate?
- jquery - is the variables only need to declare top of the function?
- how to append multiple string to an HTML element in jquery?
- jQuery Datatables - Showing 1 of X entries all the time
- Jquery TagIt issue using ViewBag as datasource plugin
- Show/Hide div on click using jQuery
- Ajax get request with useless parameter
- How do I access a model object in a view using jquery?
- Trying to add 1 to a Split String
- How to get first property of style attribute from HTML?
- Slide Down Animation with Jquery
- $modal.modal is not a function in FooTable
- Get attribute from element
- Putting PHP echo into a button's innerHTML doesn't work
- get the `rel` attribute value of the first element with class yyyxx
- How to write the following code with less lines
- Printed key and values from a Javascript object is duplicated
- Capitalize first letter of each word pulled from mysql with PHP/jQuery
- Is there a way to access a Css style through Jquery
- Simple jQuery syntax help, don't know where I've gone wrong
- Change DIV class 3 times in a row and loop it
- need help replicating jQuery's addClass function
- Set column in datatables according a specific JSON structure
- Elements flash up before fading out again
- JQuery Percentage Increases as User Scrolls
- Randomly positioning an element via css with jquery
- Replace Id with name
- Duplicate modal shown event
- jQuery POST to PHP appears in browser, but not the PHP file
- cannot embedded element loaded from ajax
- How to append a dom element inside another dom element but in first position in jquery
- Jquery show different data-id per each li on mouseover
- jQuery Div Scroll Down After Each Append
- $.ajax() joining two data objects
- jQuery ColorBox confirm override modal dialog?
- Stop simple JavaScript slideshow after one loop
- JavaScript SlideUp/SlideDown making my footer jumpy after slide
- Issue while setting html of div using the jquery html() method
- SSL + Jquery + Ajax
- Jquery - Insert value on append element
- Selecting option in a list not working in IE
- How to format date like "July 14, 2014" in javascript/jQuery?
- Move all elements after a selected li element to the start using jquery
- MvcFileUploader add/edit custom field
- How to Compare String with Hashtable object in javascript
- Freebase Suggest with Chosen Plugin multiple selection
- Jquery DataTable unable to add rows using table.rows.add method
- How to add a JavaScript function with comma separated id's into the ontouchend attribute of an element via jQuery?
- Jquery not working properly?
- rotating an element based on how many yes radioboxes are clicked
- Execute a conditional only if another conditional has already been executed
- JQuery DataPicker not working in Internet Explorer 7
- Get Value from localStorage and append to iframe URL
- JQuery UI selectmenu not displaying correctly
- Why the fiddle is not working and there is a time lag behind in following case?
- How do I keep application.js in my Rails app from getting too big, and how do I structure it?
- Passing value in HTML URL link
- How to pass multiple functions in document.ready
- DataTables jquery plugin not working, get a blank page?
- Internet Explorer works very slowly executing JS code
- Unable to set width of a div
- Unobtrusive jQuery html templating
- jQuery or Javascript alert on back button
- Highlight button when radio button is checked
- Create base64 string from HTML
- Refresh page after submit doesn't work
- jquery and mvc .net : action return json returns "object"
- How to display a loading progress bar when jQuery function is executing?