msb Posted October 20, 2005 Posted October 20, 2005 Hello, Does anyone know of a script to display the Time and Date in text format on a webpage? I would need it to display time from a timezone different to the server time. Thanks in advance. Quote
newhorizonz Posted October 20, 2005 Posted October 20, 2005 Hello, Does anyone know of a script to display the Time and Date in text format on a webpage? I would need it to display time from a timezone different to the server time. Thanks in advance. You can setup a Live clock in DHTML: http://www.dynamicdrive.com/dynamicindex6/clock2.htm I'm just looking to see what I use for date Quote
newhorizonz Posted October 20, 2005 Posted October 20, 2005 Heres a Perl script that displays the date (and optional greeting) along with the time the page loaded (static). Once set up up you can put it into each page using Server Side Includes #!/usr/bin/perl ######################################################### # Junies Creations # # Advanced Greeter with Date and Time # # v 2.0 # # Copyright © 2001 by Junies Creations # # http://juniescreations.hypermart.net # ######################################################### # Last Updated 04/13/01 # To read this file properly set the text Font to Fixedsys the Style to # Regular and the Size to 10 with Word Wrap OFF. # # Almost all text files including scripts use this format. This is the # way text is shown in DOS or any other NON-Windows view. # Define user variables ####################################################################### # Debug Information - Turn this on if you are having Time problems # 0 = Off # 1 = On $debug = 0; # Font Color for all text printed. Type color name, example black # or type the HTML numbers, example #000000 $fontcolor = "white"; # Font Style for all text printed $fontstyle = "arial"; # Font Size for all text printed $fontsize = "1"; # How should everything be displayed? (Left, Center, Right) $align = "right"; # Should greeting, date, and time be on the same line or on their own? # Greeting will be right next to the greeting image No matter either setting # 0 = Same Line # 1 = Their own lines $dline = 0; # How do you want to display the Greeting? # 0 = NO Greeting - If this is set don't worry about where the images are # 1 = Greeting without Images - If this is set don't worry about where the images are # 2 = Greeting with Images - Set where the images are below $gdisplay = 0; # The default greetings you can change them @greeting = ("Good Morning","Good Afternoon","Good Evening"); # Where are the images stored - Make sure to keep the trailing backslash / $imagestored = "http://www.yoursite.com/images/"; # Image names - Only change if you rename these files @image = ("image1.gif","image2.gif","image3.gif"); # Do you want the Weekday shown? Monday, Tuesday, etc. # 0 = Not Shown # 1 = Show it $wdisplay = 1; # How do you want the Date Displayed? # 0 = NO Date # 1 = June 14 # 2 = June 14, 2000 # 3 = 6/14/00 # 4 = 6-14-00 # 5 = 14/6/00 # 6 = 14-6-00 $ddisplay = 2; # Time Zone information. What Time Zone are you in? # 0 = Use you website server time zone # To set your time zone -- Set $timezone to 0 and then add or # subtract hours as needed. Examples subtract 5 hours # $timezone = -5; or add 5 hours $timezone = +5; $timezone = 1; # How do you want the Time Displayed? # 0 = No Time # 1 = 1:34 PM # 2 = 1:34:23 PM # 3 = 13:34 # 4 = 13:34:23 $tdisplay = 1; # End of user variables ####################################################################### @month = ("January","February","March","April","May","June","July", "August","September","October","November","December"); @day = ("Sunday","Monday","Tuesday","Wednesday", "Thursday","Friday","Saturday"); $tday = ""; $greet = ""; $gtype = 0; $newyear = 0; # Get the Date from the users computer $timezone = $timezone * 3600; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time+$timezone); # Y2k Patch probley will be needed $yyear = 1900 + $year; # Y2K Patch $newyear = $yyear - 2000; # Find the year in 2 digit format if($newyear < '10'){ # If it's a single number add a zero $newyear = "0$newyear"; # that way it shows 2 digits } $newmonth = $mon + 1; # Perl starts at 0 and calander starts # at 1 if($hour > '23'){ # Checks to see if it Midnight $hour = 12; # Makes it display the hour 12 $tday = "AM"; # Display AM } elsif($hour > '12'){ # Get rid of the Military time and $hour = $hour - 12; # put it into normal time $tday = "PM"; # If past Noon and before Midnight set } # the time as PM else { $tday = "AM"; # If it's past Midnight and before Noon } # set the time as AM if($hour eq '12'){ # 12 O'clock Noon falls thru all the steps $tday = "PM"; # so make it read PM. Otherwise the above } # else statement makes it AM if($hour <= '0'){ # When it is Midnight the hour is 0 this $hour = 12; # makes the hour 12 or Midnight $tday = "AM"; # Extra Check } if($min < '10'){ # Fixes the display of Minutes below 10 $min = "0$min\n"; # it displays 03 instead of 3 } if($sec < '10'){ # Fixes the display of Seconds below 10 $sec = "0$sec\n"; # it displays 03 instead of 3 } if($hour < '6' || $hour eq '12' && $tday eq "PM") { $greet = $greeting[1]; # If it is 12 - 5 PM print the $gtype = 1; # greeting Good Afternoon } if($hour >= '6' && $hour < '12' && $tday eq "PM") { $greet = $greeting[2]; # If it is 6 - 11 PM print the $gtype = 2; # greeting Good Evening } if($tday eq "AM") { # Else it is moring and print $greet = $greeting[0]; # greeting Good Morning $gtype = 0; } if($dline eq '0'){ # How is everything printed? All $dline = "  "; # on the same line. } else{ $dline = "<br>"; # Or on their on lines. } # Generate a HTML page to print to print "Content-type: text/html\n\n"; print "<html>\n<head><title>Simple Date Script</title></head>\n<body>\n"; print "<font color='$fontcolor' face='$fontstyle' size='$fontsize'><p align='$align'>\n"; # Print the Greeting if($gdisplay eq '1'){ print "$greet\n"; } if($gdisplay eq '2'){ print "<img src='$imagestored$image[$gtype]' alt='$greet'>\n"; print " $greet\n"; } # Show the Weekday if($wdisplay eq '1'){ $wdisplay = $day[$wday]; print "$dline$wdisplay "; } else{ $wdisplay = ""; } # Print the Date if($ddisplay eq '1'){ print "$dline$month[$mon] $mday\n"; } if($ddisplay eq '2'){ print "$dline$month[$mon] $mday, $yyear\n"; } if($ddisplay eq '3'){ print "$dline$newmonth/$mday/$newyear\n"; } if($ddisplay eq '4'){ print "$dline$newmonth-$mday-$newyear\n"; } if($ddisplay eq '5'){ print "$dline$mday/$newmonth/$newyear\n"; } if($ddisplay eq '6'){ print "$dline$mday-$newmonth-$newyear\n"; } # Print the Time if($tdisplay eq '1'){ print "$dline$hour:$min $tday \n"; } if($tdisplay eq '2'){ print "$dline$hour:$min:$sec $tday  \n"; } if($tdisplay eq '3'){ if($tday eq "PM" && $hour < '12'){ $hour = $hour + 12; } print "$dline$hour:$min  \n"; } if($tdisplay eq '4'){ if($tday eq "PM" && $hour < '12'){ $hour = $hour + 12; } print "$dline$hour:$min:$sec  \n"; } # Debug Information Area. Turn it on above in the "Define user variables". if($debug eq '1'){ print "<strong>Debug Information --</strong>\n"; print "Second - $sec, Minute - $min, Hour - $hour, Day - $mday, Month - $mon, Year - $year, Y2K Year Fix - $yyear, Weekday - $wday, Year day - $yday , ISDST - $isdst, Auctal Month - $newmonth, Auctal Year - $newyear, Auctal Weekday - $wdisplay, AM or PM - $tday, Image Used - $image[$gtype], Greeting - $greet\n"; } print "</font></body>\n</html>\n"; exit; # --- That's It! Quote
msb Posted October 20, 2005 Author Posted October 20, 2005 Thanks for the script. Do you know the html for the server side include? Also, I understand this will display a static time which will be the time the page loaded. Can it be configured so that the time updates in realtime? Quote
msb Posted October 20, 2005 Author Posted October 20, 2005 I found the ultimate Time and Date script.. http://www.maxxblade.co.uk/clock/ You can have the output displayed in the page, status or title bars and it has a plethora of options to choose from. Quote
carbonize Posted October 21, 2005 Posted October 21, 2005 I found the ultimate Time and Date script.. http://www.maxxblade.co.uk/clock/ You can have the output displayed in the page, status or title bars and it has a plethora of options to choose from. Things like that are why I have Firefox set to not allow javascript to change the text in the status bar. Personally I'd suggest getting one of dynamicdrive.com that does what you want and nothing more. That way the file size will be smaller and save your bandwidth (a little). Quote
newhorizonz Posted October 22, 2005 Posted October 22, 2005 (edited) Thanks for the script. Do you know the html for the server side include? Also, I understand this will display a static time which will be the time the page loaded. Can it be configured so that the time updates in realtime? Assuming you have named the script 'date.pl' then you call it by putting the following at the point in the html where you want it to appear: <!--#include virtual="cgi-bin/date.pl" --> No it won't do real time - that's where the DHTML script comes in. You could use a combination of that and date.pl but configure date.pl so that it does not show the time (date only) Edited October 22, 2005 by newhorizonz Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.