date and time

cuteboytm

New Member
Messages
7
Reaction score
0
Points
0
Code:
   [B]<script language=Javascript1.2>[/B]
<!--

var tags_before_clock = "<b>It is now "
var tags_middle_clock = "on"
var tags_after_clock  = "</b>"

if(navigator.appName == "Netscape") {
document.write('<layer id="clock"></layer><br>');
}

if (navigator.appVersion.indexOf("MSIE") != -1){
document.write('<span id="clock"></span>');
}

DaysofWeek = new Array()
  DaysofWeek[0]="Sunday"
  DaysofWeek[1]="Monday"
  DaysofWeek[2]="Tuesday"
  DaysofWeek[3]="Wednesday"
  DaysofWeek[4]="Thursday"
  DaysofWeek[5]="Friday"
  DaysofWeek[6]="Saturday"

Months = new Array()
  Months[0]="January"
  Months[1]="February"
  Months[2]="March"
  Months[3]="April"
  Months[4]="May"
  Months[5]="June"
  Months[6]="July"
  Months[7]="August"
  Months[8]="September"
  Months[9]="October"
  Months[10]="November"
  Months[11]="December"

function upclock(){
var dte = new Date();
var hrs = dte.getHours();
var min = dte.getMinutes();
var sec = dte.getSeconds();
var day = DaysofWeek[dte.getDay()]
var date = dte.getDate()
var month = Months[dte.getMonth()]
var year = dte.getFullYear()

var col = ":";
var spc = " ";
var com = ",";
var apm;

if (date == 1 || date == 21 || date == 31)
  {ender = "<sup>st</sup>"}
else
if (date == 2 || date == 22)
  {ender = "<sup>nd</sup>"}
else
if (date == 3 || date == 23)
  {ender = "<sup>rd</sup>"}

else
  {ender = "<sup>th</sup>"}

if (12 < hrs) {
apm="<font size='-1'>pm</font>";
hrs-=12;
}

else {
apm="<font size='-1'>am</font>";
}

if (hrs == 0) hrs=12;
if (hrs<=9) hrs="0"+hrs;
if (min<=9) min="0"+min;
if (sec<=9) sec="0"+sec;

if(navigator.appName == "Netscape") {
document.clock.document.write(tags_before_clock+hrs+col+min+col+sec+apm+spc+tags_middle_clock+spc+day+com+spc+date+ender+spc+month+com+spc+year+tags_after_clock);
document.clock.document.close();
}

if (navigator.appVersion.indexOf("MSIE") != -1){
clock.innerHTML = tags_before_clock+hrs+col+min+col+sec+apm+spc+tags_middle_clock+spc+day+com+spc+date+ender+spc+month+com+spc+year+tags_after_clock;
}
}

setInterval("upclock()",1000);
//-->
[B]</script>[/B]
 

eminemix

Member
Messages
350
Reaction score
0
Points
16
You could try a php alternative too :
<?php
// Assuming today is: March 10th, 2001, 5:16:18 pm

$today = date("F j, Y, g:i a"); // March 10, 2001, 5:16 pm
$today = date("m.d.y"); // 03.10.01
$today = date("j, n, Y"); // 10, 3, 2001
$today = date("Ymd"); // 20010310
$today = date('h-i-s, j-m-y, it is w Day z '); // 05-16-17, 10-03-01, 1631 1618 6 Fripm01
$today = date('\i\t \i\s \t\h\e jS \d\a\y.'); // It is the 10th day.
$today = date("D M j G:i:s T Y"); // Sat Mar 10 15:16:08 MST 2001
$today = date('H:m:s \m \i\s\ \m\o\n\t\h'); // 17:03:17 m is month
$today = date("H:i:s"); // 17:16:17
?>
 

lambada

New Member
Messages
2,444
Reaction score
0
Points
0
But the PHP one relies on the server time. Which may well be different from the users time because of timezones etc.
 

DefecTalisman

Community Advocate
Community Support
Messages
4,148
Reaction score
5
Points
38
Talking of date and time. When I try and get a GMT time from the server it appears to be an hour behind what I would assume to be the GMT time.
 

Sohail

Active Member
Messages
3,055
Reaction score
0
Points
36
Thanks for the script! :D I'd rather use PHP since it's more reliable...
 

lambada

New Member
Messages
2,444
Reaction score
0
Points
0
Talking of date and time. When I try and get a GMT time from the server it appears to be an hour behind what I would assume to be the GMT time.

Don't forget to allow for Daylight Savings Time which may account for this 'error' you're seeing.
 

DefecTalisman

Community Advocate
Community Support
Messages
4,148
Reaction score
5
Points
38
That would make sense. But we dont have daylight savings in my country. Humor me on this, when daylight savings is active does this mean that GMT is actually GMT+1?
 
Top