I need a 24 hr i.e 00:00 to 23:59 timepicker in javascript.
Precisely, the requirement is such that the database format are 24 hr timestamps. Hence I cant use am or pm time pickers..

Plz help guyzz..

Recommended Answers

All 3 Replies

I'm not sure what you mean by "timepicker" but maybe you want something like this:

function getDate24(d) {
	try { return d.getHours() + ':' + d.getMinutes(); }
	catch(e) { return false; }

which returns a hh:mm string when fed with a javascript Date. If something other than a Date is passed in, then false will be returned, which you can test for and take appropriate alternative action. This approach will prevent generating a javascript error and consequential crash.

Sample call, for current local computer time, would be:

var timeStr24 = getDate24(new Date());



Nice link.

Blacklister, please ignore my rubbish above. I now know what you mean by Timepicker. It's obvious when one has one's thinking head on.


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.