Click here to Skip to main content
11,929,675 members (53,327 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


17 bookmarked

Displaying the clients current date

, 14 Feb 2000 CPOL
Rate this:
Please Sign up or sign in to vote.
A simple routine to display the current date in the clients browser

Here's a simple set of functions to display the clients date. With the internet being a global system, displaying the date on server may bear no resemblence to the clients date. Not everyone lives by US Eastern Standard Time, so the following script will give your pages a little more local content than is possible using server side scripting.

<script Language="JavaScript">
function GetDay(nDay)
	var Days = new Array("Sunday","Monday","Tuesday","Wednesday",
	return Days[nDay]

function GetMonth(nMonth)
	var Months = new Array("January","February","March","April","May","June",
	return Months[nMonth] 	  	 

function DateString()
	var Today = new Date();
	var suffix = "th";
	switch (Today.getDate())
		case 1:
		case 21:
		case 31: 
			suffix = "st"; break;
		case 2:
		case 22:
			suffix = "nd"; break;
		case 3:
		case 23:
			suffix = "rd"; break;

	var strDate = GetDay(Today.getDay()) + " " + Today.getDate();
	strDate += suffix + " " + GetMonth(Today.getMonth()) + ", " + Today.getYear();
	return strDate

To use this in your web pages, just include the above script somewhere, and add the following lines:

<script Language="JavaScript">
document.write("<p>Today is " + DateString() + "</p>\n");


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Chris Maunder
Founder CodeProject
Canada Canada
Chris is the Co-founder, Administrator, Architect, Chief Editor and Shameless Hack who wrote and runs The Code Project. He's been programming since 1988 while pretending to be, in various guises, an astrophysicist, mathematician, physicist, hydrologist, geomorphologist, defence intelligence researcher and then, when all that got a bit rough on the nerves, a web developer. He is a Microsoft Visual C++ MVP both globally and for Canada locally.

His programming experience includes C/C++, C#, SQL, MFC, ASP, ASP.NET, and far, far too much FORTRAN. He has worked on PocketPCs, AIX mainframes, Sun workstations, and a CRAY YMP C90 behemoth but finds notebooks take up less desk space.

He dodges, he weaves, and he never gets enough sleep. He is kind to small animals.

Chris was born and bred in Australia but splits his time between Toronto and Melbourne, depending on the weather. For relaxation he is into road cycling, snowboarding, rock climbing, and storm chasing.

You may also be interested in...

Comments and Discussions

Generalhi Pin
chheplo12-Feb-05 19:39
memberchheplo12-Feb-05 19:39 
Generalserver time running in client side Pin
shafeek18-Sep-00 0:51
sussshafeek18-Sep-00 0:51 
GeneralRe: server time running in client side Pin
Anonymous7-Mar-02 1:15
memberAnonymous7-Mar-02 1:15 
GeneralRe: server time running in client side Pin
Anonymous22-Apr-02 22:54
memberAnonymous22-Apr-02 22:54 
GeneralRe: server time running in client side Pin
Anonymous22-Apr-02 22:58
memberAnonymous22-Apr-02 22:58 
GeneralRe: server time running in client side Pin
Anonymous4-May-05 2:10
sussAnonymous4-May-05 2:10 
Questionhow to read a html file and convert it to one string Pin
guy10-Aug-00 6:31
sussguy10-Aug-00 6:31 
GeneralClient Date time and Zone Pin
Sanjive Agarwal20-Apr-00 5:09
sussSanjive Agarwal20-Apr-00 5:09 
GeneralRe: Client Date time and Zone Pin
adhit30-May-01 17:19
memberadhit30-May-01 17:19 
QuestionWhat about international language Pin
Duncan Jones22-Feb-00 23:37
sussDuncan Jones22-Feb-00 23:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.151126.1 | Last Updated 15 Feb 2000
Article Copyright 2000 by Chris Maunder
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid