Log in

View Full Version : Looking for "Date & Time Script"



Cheng
05-05-2008, 04:47 PM
Hi.

Is there a "Date & Time Script" available which can be set to not just display the current date & time but can be set to show different time zones?
And especially show the date in languages like greek or russian for example.
If something like this is available please link me to it.

Thanks in advance,

Medyman
05-05-2008, 06:58 PM
Do you have PHP available on your server?

If so...
Look into the date() and time() functions. You should very easily be able to write your own script.

Some resources:
http://us3.php.net/datetime
http://us.php.net/date
http://us.php.net/manual/en/function.time.php
http://www.tutorialized.com/tutorials/PHP/Date-and-Time/1
http://www.tizag.com/phpT/phpdate.php
http://www.wdvl.com/Authoring/Languages/PHP/Date_Time/

Cheng
05-05-2008, 07:10 PM
.......thanks for your reply.
The site I'm creating isn't on a server yet but when it's finished it shouldn't be a problem to host it on a server with PHP support.
Anyway, I'm not that much of a coder or script writer but I'll go and have a look at the links you provided and see if I can manage to get it done.
Thanks again.......

Cheng
05-06-2008, 06:00 PM
.......thanks again for the links but it was a little to complex for me or probaly I didn't understand it.

I went for this script (see below) and I figured out how to change it to special caracters i.e. russian or greek or whatever for the weekdays and month.

The script needed to be opened in Notepad and then saved as UTF-8 with the special caraters and then it worked.

The time zone values are:

System Time & Date

function tS(){ x=new Date(); x.setTime(x.getTime()); return x; }
UTC

function tS(){ x=new Date(tN().getUTCFullYear(),tN().getUTCMonth(),tN().getUTCDate(),tN().getUTCHours(),tN().getUTCMinutes(),tN().getUTCSeconds()); x.setTime(x.getTime()); return x; }
GMT-1

function tS(){ x=new Date(tN().getUTCFullYear(),tN().getUTCMonth(),tN().getUTCDate(),tN().getUTCHours(),tN().getUTCMinutes(),tN().getUTCSeconds()); x.setTime(x.getTime()-3600000); return x; }
GMT

function tS(){ x=new Date(tN().getUTCFullYear(),tN().getUTCMonth(),tN().getUTCDate(),tN().getUTCHours(),tN().getUTCMinutes(),tN().getUTCSeconds()); x.setTime(x.getTime()+0); return x; }
GMT+1

function tS(){ x=new Date(tN().getUTCFullYear(),tN().getUTCMonth(),tN().getUTCDate(),tN().getUTCHours(),tN().getUTCMinutes(),tN().getUTCSeconds()); x.setTime(x.getTime()+3600000); return x; }
GMT+2

function tS(){ x=new Date(tN().getUTCFullYear(),tN().getUTCMonth(),tN().getUTCDate(),tN().getUTCHours(),tN().getUTCMinutes(),tN().getUTCSeconds()); x.setTime(x.getTime()+7200000); return x; }

And so on - (3600000 intervals for each hour + or -).

Call the script where you want it to appear with:

<script type="text/javaScript">dT();</script>

Also put a link in the HTML head for the js file:

<script type="text/javaScript" src="date_time_script.js"></script>

function tS(){ x=new Date(tN().getUTCFullYear(),tN().getUTCMonth(),tN().getUTCDate(),tN().getUTCHours(),tN().getUTCMinutes(),tN().getUTCSeconds()); x.setTime(x.getTime()+10800000); return x; }
function tN(){ return new Date(); }
function lZ(x){ return (x>9)?x:'0'+x; }
function dE(x){ if(x==1||x==21||x==31){ return 'st'; } if(x==2||x==22){ return 'nd'; } if(x==3||x==23){ return 'rd'; } return 'th'; }
function dT(){ if(fr==0){ fr=1; document.write('<font size=2 font color=#000000 face=Verdana><b><span id="tP">'+eval(oT)+'</span></b></font>'); } document.getElementById('tP').innerHTML=eval(oT); setTimeout('dT()',1000); }
function y4(x){ return (x<500)?x+1900:x; }
var dN=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'),mN=new Array('January','February','March','April','May','June','July','August','September','October','November','December'),fr=0,oT="dN[tS().getDay()]+','+' '+mN[tS().getMonth()]+' '+tS().getDate()+dE(tS().getDate())+' '+y4(tS().getYear())+' '+'-'+' '+lZ(tS().getHours())+':'+lZ(tS().getMinutes())+':'+lZ(tS().getSeconds())+' '";
No PHP server required and maybe some of you guys have use for this script as well.

P.S
What I didn't figure out yet is how to change the font size into px values.

Cheers.......