Jump to content

JAVASCRIPT - CURRENT TIME


Recommended Posts

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 post
Share on other sites
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 post
Share on other sites

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 post
Share on other sites

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 by thescientist
Link to post
Share on other sites

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 post
Share on other sites
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...