
The output will be like this:
And the required code, to be added is this:
<script language="Javascript">
<!--
var dayName = new Array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
var monName = new Array ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")
var now = new Date
document.write("Today is " + dayName[now.getDay()] + ", " + monName[now.getMonth()] + " "+now.getDate() +".")
//-->
</script>
There's an even simpler code, to display date(like this):
Here's the code:
<script language="Javascript">And to show current time in text format, like this:
<!--
var now = new Date
document.write(now.getDate() + "/" + now.getMonth() + "/" + now.getYear())
//-->
</script>
Add this code:
<script>
atoj = new Date();
atoj1= atoj.getHours();
atoj2 = atoj.getMinutes();
atoj3= atoj.getSeconds();
if(atoj1==0){atoj4=" AM";atoj1=12}
else if(atoj1 <= 11){atoj4=" AM"} else if(atoj1 == 12){atoj4=" PM";atoj1=12} else if(atoj1 >= 13){atoj4=" PM";atoj1-=12}
if(atoj2 <= 9){atoj2="0"+atoj2} document.write(""+atoj1+":"+atoj2+":"+atoj3+""+atoj4+""+"");
</script>
17 comments
Write commentsThanks for the code. I translated days and months in my own language.
Replycool ;) !
ReplyMan, how do I change the color of the date?
ReplyHello Felix,
ReplyYou have to add two more lines of code to any of the above code, like this:
<span style="color: red;">
CODE FOR DATE/TIME HERE
</span>
How do I change the time zone for the clock and date?
ReplyYou don't have to do that, this script automatically takes the date from the computer where the site is being viewed, so every visitor will automatically see the time/date of his/her own time zone.
ReplyMy blog is in Spanish and I modified the first code for it to fit the language... it was just a try... and it worked. Thanks a lot.
ReplyIf you want to see the result, this is it. http://palabrasalasecho.blogspot.com
Thank you very much for the code..
ReplyI had been loooking for it so long and just found your method..
Thank you very much!!
Posted in my language Tamil:
aalunga.blogspot.com
hi everyone but i need to show the Standard time on my site as some system may have wrong time so they will see the wrong time na.....!
ReplyWWW.eceinjntu.blogspot.com
Thanks for this.
ReplyHow can I bold it?
Hello, I would like to put the date as a calender like you show on this tutorial. But where is the javascript?
ReplyHi.. how do i enlarge the font size ???
ReplyReally nice and simple!
ReplyAny chance of a 24 hour clock version?
Thx.
How to add year in first code please?
Replytried adding the first code in my post template but of no use..please help.I want the date to appear in my post template(i.e when i write a new post the date format as in the first code must be there)
ReplyLooking for a html widget like this - but shows the day of the week. BTW your anti robot test is too hard to read.
ReplyI have tried to combine the first and second way to get the format: "27 August 2012".
Replybut what I find in this year is "27 Agust 113".
Then I changed the code "getDay" to "getFullYear" and succeed. :)
thank you
Comments are moderated on this blog
Allowed HTML tags: <b>, <i> and <a>
Comment Like This! and Optimize your blog EmoticonEmoticon