JRS: In article <w9lHe.80648$5V4.77990@pd7tw3no>, dated Mon, 1 Aug 2005
08:35:40, seen in news:comp.lang.javascript, Noozer <do*******@me.here>
posted :
Are there any functions in javascript that can convert different time
formats to a known format (24 hour clock)... 5pm -> 17:00 or 5:00 to 05:00,
etc. ???
Yes.
Assuming that I get the input into a 24 hour format, how can I create a full
time/date variable with todays date and the users entered time?
with (D = new Date()) setHours(H, M, S)
or with (D = new Date()) setUTCHours(H, M, S)
where H M S are numbers or strings for hours minutes seconds.
N.B. VERY ancient browsers may not allow multiple parameters in
setHours().
Finally, if the entered time is earlier than the current time, how can I
create the above date/time combination using tomorrows date?
Add
if (D < new Date()) D.setDate(D.getDate()+1)
or if (D < new Date()) D.setUTCDate(D.getUTCDate()+1)
If there is any possibility of the actual time, or of H M S, being
affected to Summer Time clock changes in Spring and Autumn, then test
carefully that what happens is satisfactory.
If efficiency matters, which is unlikely, do parameterless new Date()
only once. That's also vital if the user may be working at local (or
UTC) midnight.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.