Jump to content

time & date


Patriot

Recommended Posts

i want to make a small script so that on a certain day of a certain month and possibly a certain year down the road when you load the page it might say happy birthday, or merry christmas, or whatever else you could think of, happy anniversary.i messed with the time one and think i got that figured out, so now im messing with the dayexample:if the day is the 25th of December, i want it to output merry christmas wherever i put the script.and if the day is anything else i would just want it to say whatever.

Link to comment
Share on other sites

Here is how you would check for Christmas

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;if(now.getDate() == 25 && monName[now.getMonth()] == "December"){    alert('Merry Christmas');}

Link to comment
Share on other sites

Here is how you would check for Christmas
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;if(now.getDate() == 25 && monName[now.getMonth()] == "December"){    alert('Merry Christmas');}

thanks for the help i new it could be done, i got it added in with the rest of the script and it works great. as soon as i finish up the basics on the page i will put a link up so everybody can see it. what im trying to do is make it so say on christmas instead of showing the normal site contents it will put up a christmas colored page with christmas type ###### on it, or the header all year might say hello and on my birthday it will say happy birthday to me, it is a cool idea you gotta admit :) really i was reading the tutorials and came up with the idea and just been playing with it since, all the stuff on my site is random ideas that i came across while reading the tutorials and i have just been trying to get them to do different things, maybe i will try to put an actual site with some real content one of these days, but untill i do .....................click the link below
Link to comment
Share on other sites

thanks for the help i new it could be done, i got it added in with the rest of the script and it works great. as soon as i finish up the basics on the page i will put a link up so everybody can see it. what im trying to do is make it so say on christmas instead of showing the normal site contents it will put up a christmas colored page with christmas type ###### on it, or the header all year might say hello and on my birthday it will say happy birthday to me, it is a cool idea you gotta admit :) really i was reading the tutorials and came up with the idea and just been playing with it since, all the stuff on my site is random ideas that i came across while reading the tutorials and i have just been trying to get them to do different things, maybe i will try to put an actual site with some real content one of these days, but untill i do .....................click the link below

How does that work, exactly?
Link to comment
Share on other sites

I'll add some comments to it, so yuo can figure it out.

var dayName = new Array ("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");//Useless, not needed for this scriptvar monName = new Array ("January","February","March","April","May","June","July","August","September","October","November","December");//putting the months of the year in an array, so they can be accessed by the month number.var now = new Date;//gets the current day of the month.if(now.getDate() == 25 && monName[now.getMonth()] == "December")/*checks if the day is the 25th of december. How it does this is monName contains an array of the months, and getMonth gets the number of the current month, so if the current month is april, it'll get the 4th value in the array, which is april.*/{   alert('Merry Christmas');}

Link to comment
Share on other sites

the code above is awsome you can actually use it for at least a few different things that i hae been messing with.i used it in a header on a test page so that the header displays the time and date, and if it is say christmas day it will say merry christmas instead of the time and date, or new years will say happy new years instead.i also messed with it in the body and have a all the time content part and then a christmas part and new years part, the page i am testing with isnt online or i would give you a link so you can see what i did/am doing with it.

<html><head><style type="text/css">div.container {	width:100%;	margin:0px;	border:2px solid black;	line-height:150%;}div.left {	float:left;	width:23%;	margin:0;	border-right:2px solid black;	padding:1px;}div.content {	margin-left:23%;	padding:50px;}.test1 {position: absolute; top: 200px;     left: 250px;   background-color: red;   color:black; font-size:100%; width:310;}.test2 {position: absolute; top: 200px;     right: 50px;   background-color: white; color:black; font-size:100%; width:310;}.test3 {position: absolute; bottom: 0px; left: 250px;      background-color: blue;  color:black; font-size:100%; width:310;}.test4 {position: absolute; bottom: 0px;  right: 50px;     background-color: green; color:black; font-size:100%; width:310;}<div class="1header"><script type="text/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;if(now.getDate() == 25 && monName[now.getMonth()] == "December"){document.write ("Merry Christmas");}else if(now.getDate() == 1 && monName[now.getMonth()] == "January"){document.write ("Happy New Year");}else{var d=new Date()var weekday=new Array(7)weekday[0]="Sunday,"weekday[1]="Monday,"weekday[2]="Tuesday,"weekday[3]="Wednesday,"weekday[4]="Thursday,"weekday[5]="Friday,"weekday[6]="Saturday,"document.write("Today it is " + weekday[d.getDay()])document.write(" ")var b=new Date()var month=new Array(12)month[0]="January"month[1]="February"month[2]="March"month[3]="April"month[4]="May"month[5]="June"month[6]="July"month[7]="August"month[8]="September"month[9]="October"month[10]="November"month[11]="December"document.write("" + month[b.getMonth()])document.write(" ")var c = new Date()document.write(c.getDate())document.write ("<b>, </b>")var d = new Date()document.write(d.getYear())document.write(" the time is ")var e = new Date()document.write(e.getHours())var f = new Date()document.write ("<b>:</b>")document.write(f.getMinutes())}</script></div><div class="content"><p class=welcome><script type="text/javascript">var d = new Date()var time = d.getHours()if (time<11){document.write("<b>Good morning,</b>")}else if (time>12 && time<17){document.write("<b>Good afternoon,</b>")}else if (time>17 && time<24){document.write("<b>Good evening,</b>")}else{document.write("<b>Hello World!</b>")}</script></p><br><script type="text/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;if(now.getDate() == 25 && monName[now.getMonth()] == "December"){document.write ("<p class=cd><b>Merry Christmas</p><br>");}else if(now.getDate() == 1 && monName[now.getMonth()] == "January"){document.write ("<p class=nyd><b>Happy New Year</p><br>");}else{document.write ("<p class=test1><table><tr><td><img src='c:/WINDOWS/Desktop/100_0880.JPG'    alt='' width=160 height=160></td><td>This is our new house<br>we moved in on<br>00-00-00.</td></tr></table>");document.write ("<p class=test2><table><tr><td><img src='c:/WINDOWS/Desktop/100_0876.JPG'    alt='' width=160 height=160></td><td>This is Bradley<br>he is a purebred<br>Labrador Retreiver.</td></tr></table>");document.write ("<p class=test3><table><tr><td><img src='c:/WINDOWS/Desktop/6-23-05 007.JPG' alt='' width=160 height=160></td><td>This is a picture of Corey at his beret ceramony in<br>Fort Knox, Kentucky.</td></tr></table>");document.write ("<p class=test4><table><tr><td><img src='c:/WINDOWS/Desktop/100_0880.JPG'    alt='' width=160 height=160></td><td>This is our new house<br>we moved in on<br>00-00-00.</td></tr></table>");}</script></div></body></html>

this is just little parts of what im messing with, i write everything the long way, so if i posted the entire code it would take more space than allowed.

Link to comment
Share on other sites

I am trying to do a time and date script as well. I have figured everything out except for how to get the year to be "2005" rather than "05" for example. The only think that I could find to make it work is to physically type in "20" before the code in the script that calls the year. I know there must be a way to do it so the script gets it automatically, but I can't figure it out. Can anyone help me? Here is the java script:

<script type="text/javascript">function tS(){ x=new Date(); x.setTime(x.getTime()); return x; }function lZ(x){ return (x>9)?x:'0'+x; }function tH(x){ if(x==0){ x=12; } return (x>12)?x-=12:x; }function y2(x){ x=(x<500)?x+1900:x; return String(x).substring(2,4) }function dT(){ window.status=''+eval(oT)+''; document.getElementById('tP').innerHTML=eval(oT); setTimeout('dT()',1000); }function aP(x){ return (x>11)?'pm':'am'; }var dN=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'),mN=new Array('January','February','March','April','May','June','July','August','September','October','November','December'),oT="dN[tS().getDay()]+''+','+' '+mN[tS().getMonth()]+' '+(tS().getDate())+''+','+' 20'+y2(tS().getYear())+' '+'-'+' '+tH(tS().getHours())+':'+lZ(tS().getMinutes())+':'+lZ(tS().getSeconds())+' '+aP(tS().getHours())";if(!document.all){ window.onload=dT; }else{ dT(); }</script></p>

Link to comment
Share on other sites

well this is the code i use for the year and it puts 2005

var d = new Date()document.write(d.getYear())

and this is the code i use for the day, date, month, year, time.

<script type="text/javascript">var d=new Date()var weekday=new Array(7)weekday[0]="Sunday,"weekday[1]="Monday,"weekday[2]="Tuesday,"weekday[3]="Wednesday,"weekday[4]="Thursday,"weekday[5]="Friday,"weekday[6]="Saturday,"document.write("Today it is " + weekday[d.getDay()])document.write(" ")var b=new Date()var month=new Array(12)month[0]="January"month[1]="February"month[2]="March"month[3]="April"month[4]="May"month[5]="June"month[6]="July"month[7]="August"month[8]="September"month[9]="October"month[10]="November"month[11]="December"document.write("" + month[b.getMonth()])document.write(" ")var c = new Date()document.write(c.getDate())document.write ("<b>, </b>")var d = new Date()document.write(d.getYear())document.write(" the time is ")var e = new Date()document.write(e.getHours())var f = new Date()document.write ("<b>:</b>")document.write(f.getMinutes())</script>

hope this helps

Link to comment
Share on other sites

well this is the code i use for the year and it puts 2005
var d = new Date()document.write(d.getYear())

and this is the code i use for the day, date, month, year, time.

<script type="text/javascript">var d=new Date()var weekday=new Array(7)weekday[0]="Sunday,"weekday[1]="Monday,"weekday[2]="Tuesday,"weekday[3]="Wednesday,"weekday[4]="Thursday,"weekday[5]="Friday,"weekday[6]="Saturday,"document.write("Today it is " + weekday[d.getDay()])document.write(" ")var b=new Date()var month=new Array(12)month[0]="January"month[1]="February"month[2]="March"month[3]="April"month[4]="May"month[5]="June"month[6]="July"month[7]="August"month[8]="September"month[9]="October"month[10]="November"month[11]="December"document.write("" + month[b.getMonth()])document.write(" ")var c = new Date()document.write(c.getDate())document.write ("<b>, </b>")var d = new Date()document.write(d.getYear())document.write(" the time is ")var e = new Date()document.write(e.getHours())var f = new Date()document.write ("<b>:</b>")document.write(f.getMinutes())</script>

hope this helps

I am trying to keep the code I have, but just modify it. Surely it can be modified other than how I have it. However, it's not like I wll be around to see 2100, so maybe I ought to leave well enough alone.
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...