Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q147 How do you subtract X hours from a date?

You are here: irt.org | FAQ | JavaScript | Date | Q147 [ previous next ]

The following subtracts five hours from the current date and time:

<SCRIPT LANGUAGE = 'JavaScript'><!--
function y2k(number) { return (number < 1000) ? number + 1900 : number; }

var date = new Date();
var date = new Date(Date.UTC(y2k(date.getYear()),date.getMonth(),date.getDate(),date.getHours(),date.getMinutes(),date.getSeconds()) - 5*60*60*1000);
document.write(date);
//--></SCRIPT>

Feedback on 'Q147 How do you subtract X hours from a date?'

©2018 Martin Webb