View Full Version : Simple Date and Time Function

Sep 19th, 2006, 07:32 AM
I've been trying something and it's been frustrating me at how simple it must be, but no matter what i try or where I look I can't find anythign that works.

I simply need 3 functions, that set the following variables in the format as shown in the example. The rest of my code works perfectly fine, but I can't seem to get these 3 variables.

(I'm after Server time not local machine time)

var hourstamp = 01;
var minute = 23;
var second = 45;

I'm sure there is an easy way, I've just missed it. Thanks.

(If my problem isn't clear i can try to clarify it some more)

Philip M
Sep 19th, 2006, 05:53 PM
Your problem is indeed not entirely clear.

Try working with this:

var now = new Date();
var hours = now.getHours();
var mn = now.getMinutes();
var secs = now.getSeconds();

If you want to put in leading zeros when applicable, then

var hours = (now.getHours() ) toString();
if (hours.length>2) {hours = 0+hours} // concatenation

and so on.