SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Zealot Kamran's Avatar
    Join Date
    Sep 2000
    Location
    UK
    Posts
    143
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I was wondering how websites have the date at the top of their pages, i.e.

    Wednesday 18th April 2001

    Thanks

    Kam

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One way...between <head></head> add:

    Code:
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    function MakeArray(n) {
    	this.length = n
    	return this
    }
    monthNames = new MakeArray(12)
    monthNames[1] = "January"
    monthNames[2] = "February"
    monthNames[3] = "March"
    monthNames[4] = "April"
    monthNames[5] = "May"
    monthNames[6] = "June"
    monthNames[7] = "July"
    monthNames[8] = "August"
    monthNames[9] = "September"
    monthNames[10] = "October"
    monthNames[11] = "November"
    monthNames[12] = "December"
    dayNames = new MakeArray(7)
    dayNames[1] = "Sunday"
    dayNames[2] = "Monday"
    dayNames[3] = "Tuesday"
    dayNames[4] = "Wednesday"
    dayNames[5] = "Thursday"
    dayNames[6] = "Friday"
    dayNames[7] = "Saturday"
    
    function customDateString() {
    	currentDate = new Date()
    	var theDay = dayNames[currentDate.getDay() + 1]
    	var theMonth = monthNames[currentDate.getMonth() + 1]
    	msie4 = ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4 ));
    	if (msie4) {
    	    var theYear = currentDate.getYear()
    	}
    	else {
    	     var theYear = currentDate.getYear() +1900
    	}
    	return theDay + ", " + theMonth + " " + currentDate.getDate() + ", " + theYear
    }
    //-->
    </SCRIPT>
    Place this within your page where you would like it:

    Code:
    <SCRIPT LANGUAGE="JavaScript">
    document.write(customDateString())
    </SCRIPT>

  3. #3
    SitePoint Enthusiast chickaboom's Avatar
    Join Date
    Mar 2001
    Location
    Sunny southern California
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I do believe it's a javascript. Here are some from JavaScript Source:

    http://javascript.internet.com/clocks/index.html

  4. #4
    SitePoint Addict Percipient's Avatar
    Join Date
    Jun 2000
    Location
    Summerland, BC, Canada.
    Posts
    226
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Heh, I was almost finished writing an answer, and the power went out. Thankful only for a minute or so.

    Anyway, JavaScript works best if you're on a server that doesn't support anything server side, like a free server. You can also use php, if your server supports it...

    PHP Code:
    <?PHP
     
    print date ("l, F jS, Y");
    ?>
    This would give you something like "Tuesday, April 17th, 2001"

    You can also use SSI (again, only if your server supports it), but you have less control over the format of the output.

    Code:
    <!--#ECHO VAR="DATE_LOCAL" -->
    The trouble these two methods is they use the server's time, rather than the client's time. This can be overcome in PHP, if you know the client's time zone, but it's not great. JavaScript is probably the best bet. Just remember, not everyone has it turned on, though.
    Ed Rands

  5. #5
    SitePoint Zealot Kamran's Avatar
    Join Date
    Sep 2000
    Location
    UK
    Posts
    143
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Thanks very much for all the replies!

    I've gone with the JavaScript - which works fine! - thx

    Kam

  6. #6
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Of course, the javascript solution will give the system date of the client machine which may be different to that of the server depending on where in the world the client is located.

  7. #7
    Senior Webdesigner koolbrian's Avatar
    Join Date
    Dec 2000
    Location
    Mauritius
    Posts
    599
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    and how to change the fonts, color, ????? (javascript one)

    Brian

  8. #8
    Grumpy Mole Man Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,067
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Brian - just add tags setting the font and colour around the script tag like this:
    Code:
    <font face="Verdana, Arial, Helvetica, sans-serif" size=2 color="#000000"><SCRIPT LANGUAGE="JavaScript">
    document.write(customDateString())
    </SCRIPT></font>

  9. #9
    SitePoint Zealot Kamran's Avatar
    Join Date
    Sep 2000
    Location
    UK
    Posts
    143
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thx Skunk plus that post on php/mysql was great!

    Kam


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •