...

View Full Version : Javascript Date Engine



Omega9850
03-22-2012, 03:47 AM
I've been programming with Javascript for a bit now, and I've taken a lot of interest in simple Javascript AIs using the If Else method. Below is a code I've used in one of my AIs that determines the Date.


var dateengine=new Array(4);
dateengine[1]="1.0"; //Date Engine Version
dateengine[2]=new Date(); //Full Date: Day, Month, Day, Year, Military Time, Time Zone
dateengine[3]=dateengine[2].getHours(); //Military Hours
dateengine[4]=dateengine[2].getMinutes(); //Minutes (0-59)

if (dateengine[3] == 0)
{
sessionStorage.setItem("meridiem","AM");
sessionStorage.setItem("hour", dateengine[3] + 12);
}
else {}
if (dateengine[3] >= 1 && dateengine[3] <= 11)
{
sessionStorage.setItem("meridiem","AM");
sessionStorage.setItem("hour",dateengine[3]);
}
else {}
if (dateengine[3] == 12)
{
sessionStorage.setItem("meridiem","PM");
sessionStorage.setItem("hour",dateengine[3]);
}
else {}
if (dateengine[3] >= 13 && dateengine[3] <= 23)
{
sessionStorage.setItem("meridiem","PM");
sessionStorage.setItem("hour",dateengine[3] - 12);
}
else {}

if (dateengine[3] >= 0 && dateengine[3] <= 4)
{
sessionStorage.setItem("tod","Night");
}
else {}
if (dateengine[3] >= 5 && dateengine[3] <= 11)
{
sessionStorage.setItem("tod","Morning");
}
else {}
if (dateengine[3] == 12)
{
sessionStorage.setItem("tod","Noon");
}
else {}
if (dateengine[3] >= 13 && dateengine[3] <= 16)
{
sessionStorage.setItem("tod","Afternoon");
}
else {}
if (dateengine[3] >= 17 && dateengine[3] <= 19)
{
sessionStorage.setItem("tod","Evening");
}
else {}
if (dateengine[3] >= 20 && dateengine[3] <= 23)
{
sessionStorage.setItem("tod","Night");
}
else {}

var day=dateengine[2].getDate(); //Day (1-31)
var daynamedarray=new Array(7);
daynamedarray[1]="Sunday";
daynamedarray[2]="Monday";
daynamedarray[3]="Tuesday";
daynamedarray[4]="Wednesday";
daynamedarray[5]="Thursday";
daynamedarray[6]="Friday";
daynamedarray[7]="Saturday";
var daynamed=daynamedarray[dateengine[2].getDay()+1]; //Day (Saturday-Sunday)
var month=dateengine[2].getMonth()+1; //Month (1-12)
var monthnamedarray=new Array(12);
monthnamedarray[1]="January";
monthnamedarray[2]="February";
monthnamedarray[3]="March";
monthnamedarray[4]="April";
monthnamedarray[5]="May";
monthnamedarray[6]="June";
monthnamedarray[7]="July";
monthnamedarray[8]="August";
monthnamedarray[9]="September";
monthnamedarray[10]="October";
monthnamedarray[11]="November";
monthnamedarray[12]="December";
var monthnamed=monthnamedarray[month]; //Month (January-February)
var year=dateengine[2].getFullYear(); //Year (2010)

I've tested this code in Firefox, Google Chrome, Google Chromium, and Safari. They all seem to work fine. It also works on Internet Explorer, but I've only tried 9.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum