linden Posted August 1, 2011 Report Share Posted August 1, 2011 Hi,I have found a lot of javascript to put a time on my website. A lot of them are an army clock which I do not want. I want a normal clock for example 11:08 PM. Can anybody provide me the script for this. I appreciated it.Thank you,Marla Link to comment Share on other sites More sharing options...
Ingolme Posted August 1, 2011 Report Share Posted August 1, 2011 http://w3schools.com/js/js_obj_date.aspTake the hour of the date object, get the modulo and then set it to 12 if the result is 0:This portion gets the hour and the am/pm part.hour = d.getHours();if(hour > 11 || hour == 0) { a = "am";} else { a = "pm"}hour = hour % 12;hour = (hour == 0)? 12 : hour; Link to comment Share on other sites More sharing options...
Drycodez Posted August 1, 2011 Report Share Posted August 1, 2011 (edited) [] Edited August 1, 2011 by O. Samuel Link to comment Share on other sites More sharing options...
linden Posted August 1, 2011 Author Report Share Posted August 1, 2011 Hi Samuel,Thank you for your reply. It did not work. Something to do with d. on the first line.Marla http://w3schools.com/js/js_obj_date.aspTake the hour of the date object, get the modulo and then set it to 12 if the result is 0:This portion gets the hour and the am/pm part.hour = d.getHours();if(hour > 11 || hour == 0) { a = "am";} else { a = "pm"}hour = hour % 12;hour = (hour == 0)? 12 : hour; Link to comment Share on other sites More sharing options...
thescientist Posted August 1, 2011 Report Share Posted August 1, 2011 (edited) did you look at the link Ingolme gave you? you never made a date object. that's why you are having a problem with d, it's undefined. Edited August 1, 2011 by thescientist Link to comment Share on other sites More sharing options...
Ingolme Posted August 1, 2011 Report Share Posted August 1, 2011 You're supposed to study the date object at the W3Schools tutorial before trying my example. I gave you the link before and I'll give it again:http://w3schools.com/js/js_obj_date.aspI don't give code to just copy and paste, I intend to teach people. Link to comment Share on other sites More sharing options...
Don E Posted August 3, 2011 Report Share Posted August 3, 2011 You're supposed to study the date object at the W3Schools tutorial before trying my example. I gave you the link before and I'll give it again:http://w3schools.com/js/js_obj_date.aspI don't give code to just copy and paste, I intend to teach people.Hey Ingolme, I just wanted to make a quick moment to thank you(noticing you're a moderator) and EVERYONE at w3schools.com for such a wonderful and great website/resource for web design/development. It surely has helped me out big time and is my ONE STOP place for everything web related! So my gratitude and appreciation goes to you ALL. Thank you! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now