2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by urtrivedi
0

javascript-how add 12 hrs to 2011-5-11 03:33:43 PM

My date format is (yyyy-mm-dd H:I:S,)(12 hours format)
I want to add 12 hours ,24 hours,36 hours,48 hours,60 hours etc.to date.
I don't want to show it in UTC format.
please help.

0
<html>
<script lang='javascript'>
function addhours()
{
   var dt=document.getElementById('mydate').value.substr(0,10);
   var tme=document.getElementById('mydate').value.substr(11,8);

	arrdt= dt.split("-");
      arrtme=tme.split(":");
	newdt=new Date(arrdt[0],arrdt[1]-1,arrdt[2],arrtme[0],arrtme[1],arrtme[2]);
	alert(newdt);
      newdt.setHours(document.getElementById('myhours').value);
	alert(newdt);
//alert(dt);

//alert(tme);
}
</script>
<body>
<form id=frm name=frm>
Date: <input type=text name=mydate id=mydate value='2011-05-11 15:33:42'><br>
Add Hours: <input type=text name=myhours id=myhours value=12><br>
<input type=button onclick="addhours()">
</form>
</body>
</html>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.