 |
 |
 |
When and How to Display Time on a Website
Wednesday, February 23, 2005 Posted: 13:14 PM (EST)
Are websites designed for 90% of your viewing audience good enough? I think not. In a recent
conversation with a self-proclaimed webmaster I brought to his attention that using client-side JavaScript to display the current
time and date was basically flawed. The webmaster's response was that 90% of computer users have their computer clocks
properly set to the correct time.
Displaying the time and date is a good thing. It helps to reinforce
in the mind of the browser that they are viewing fresh and up
to date content. But if that time or date is incorrect, the
browser will see this as an indicative flaw and it will reflect
badly on your website and its content.
When a designer uses client-side JavaScript to display the time
and date, they rely on the clock time of the browser's computer.
If that user does not have their computer clock set to the correct
time and date then the time displayed on your web page will
also be incorrect.
The only way to ensure that the proper date is displayed on
your web page is not with the use of client-side scripting,
but by using server-side scripting, such as ASP or PHP. By using
the server-side method, the time and date will be based on the
clock time of the server and not on the clock time of the visitor's
computer. I have much more faith in server administrators to
maintain the proper clock time and date on their computers than
I do in the general browsing public.
But server-side scripting also has a flaw. You don't know in
which time zone your website visitor resides, and the server
time is always set to the time zone in which the server is located.
So if someone from -8 GMT were to visit a website on a server
located in -4 GMT, then the time displayed to that user would
be incorrect by 4 hours. In the same breath, someone from the
other side of the world could see a full one day difference
in the date.
Time Display Code : PHP
<?
$timestamp = time();
$date_time_array = getdate($timestamp);
$hours = $date_time_array["hours"];
$minutes = $date_time_array["minutes"];
$seconds = $date_time_array["seconds"];
$month = $date_time_array["mon"];
$day = $date_time_array["mday"];
$year = $date_time_array["year"];
$timestamp = mktime($hours + 1, $minutes,$seconds ,$month, $day,$year);
echo strftime( "%b %d, %Y",$timestamp);
?> |
The only way to present the correct time and date on a web page
is after a user has logged into your website and after they
have correctly allowed for any time difference by making an
adjustment in their personal settings. For this reason I will only use server-side scripting and I will only display the date
, and not the time , on pages where users do not login.
For me, every hit counts and I want 100% of my visitors from
this side of the world to see the correct date. And as a business
owner so should you.
Ron Poole is the managing editor of Hair Say Headlines and Hair Say Newsroom.
Copyright 2005 Beauty By Us Inc. All rights reserved. This material may not be published, broadcast, rewritten, or redistributed.
|
|
|