How to add 4 hours to current system time

Hi
all

I want to validate the time field so that the user can enter the time more than 3 hours from the current time

please help me out.

Thanks
MD.Samiuddin

JavaScript uses the time on your visitor’s computer as the starting point so you don’t want to use it for anything that really depends on any particular time being set.

To get the time three hours from what their computer currently thinks the time is you would use:

var time = new Date();
time.setHours(time.getHours()+3);
alert('In three hours it will be ' +time.getHours() +':'+time.getMinutes()+':'+time.getSeconds());

If you are going to be doing lots of date and time manipulations in JavaScript you might take a look at http://javascriptexample.net/dollarD.php

The code to get the time three hours from now would then be:

var time = new $D();
time.addHours(3);
alert('In three hours it will be '+time.format('H:i:s'));

Of course the extra code for the library isn’t worth it unless you are actually going to be doing a lot of date and time processing and want to make it easier to read like this.

Thanks for your help and support.

I am very grateful to you

Thanks & Regards
MD.Samiuddin