PDA

View Full Version : I want to insert local time & date in my site



leonidassavvides
05-23-2008, 03:22 PM
Wednesday 25 May 2008*|*13:01*GMT+2*|*Cyprus-EU*
I want to insert local time & date in my site , well zone is GMT+2 , below is correct for date , what about time ?


<script language="JavaScript" type="text/javascript"><!--
var months = new Array("Jan", "Feb", "Mar","Apr", "May", "Jun", "Jul","Aug", "Sep", "Oct","Nov", "Dec")
var weekdays = new Array("Sunday", "Monday", "Tuesday","Wednesday", "Thursday","Friday", "Saturday")

var today = new Date()
//-->
</script>


<script language="JavaScript" type="text/javascript"><!--
// Today is Weekday, Month Day, Year
document.write(weekdays[today.getDay()], ", ",months[today.getMonth()], " ",today.getDate(), ", ",today.getFullYear())
//-->
</script>

kuau
05-23-2008, 10:22 PM
This will work in php5 (not 4) to correct the time based on your timezone, but it is set when you load the page. If you want a live clock, you have to use something else.

echo "Original Time: ". date("h:i:s")."\n";
putenv("TZ=Cyprus-EU");
echo "New Time: ". date("h:i:s")."\n";

Anyway, it works for me. erin

leonidassavvides
05-25-2008, 02:25 PM
This is correct(js) ?


<script type="text/javascript">

var d = new Date();
gmt=d.toUTCString(); // get GMT Time/date
// document.write (d.toUTCString());
var gmt2ms = new Date(gmt.valueOf()+60*60*1000*2); // add two hours in ms
document.write(gmt2ms.toString()); // write date as Sun, 25 May 2008 14:19:30
</script>

What the
x.valueOf()
x.toString()
do ?