I want a script to receive a time in the 24 hour time format HH:mm (e.g. 18:30) and remove 15 minutes from it.
The problem is that if the time inputted was 00:00, then how do I get to 23:45?
I’m sure it’s easy if you’re in the know.
I can do this with PHP, but not with JS.
I just need the function / basic line of code that does this. I can work out how to call it etc. myself.
Thanks for any help.
John
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
/*<![CDATA[*/
function Time(time,less){
var time=time.split(':'),date=new Date(2011,6,1,time[0]*1,time[1]*1+less),hrs=date.getHours(),min=date.getMinutes();
return (hrs>9?hrs:'0'+hrs)+':'+(min>9?min:'0'+min);
}
alert(Time('4:24',-15));
alert(Time('00:00',-15));
/*]]>*/
</script>
</body>
</html>