note 69062 deleted from function.strftime by derick
| From: | derick@php.net | Date: | Sun, 11 May 2008 14:02:40 +0000 |
| Subject: | note 69062 deleted from function.strftime by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-139275@lists.php.net to get a copy of this message | ||
Note Submitter: NicSoft
----
A simple work around for displaying dates in local format is to get the browser to do it for you
using javascript.
This routine accepts a date time field from sql,
and gets the timezone offset for your server, and passes these over to the browser in the form of a
javascript script.
Javascript calculates the time difference and uses toLocaleString to display it.
function DisplaySQLDateInLocalTime($SQLDate){
list($year,$mon,$day,$hour,$min,$sec)=split('[-: ]',$SQLDate);
$TimeZoneOffset=date('Z') /60;
$JS="\n<script><!--\n";
$JS.="LocalTime = new Date();\n";
$JS.="TimeZoneOffsetInMins = LocalTime.getTimezoneOffset();\n";
$JS.="ServerTimeZoneOffset=$TimeZoneOffset;\n";
$JS.="timediff=-TimeZoneOffsetInMins - ServerTimeZoneOffset;\n";
$JS.="LocalTime = new Date(".$year.","
.($mon-1).",".$day.",".$hour.",".$min.",".$sec.");\n";
$JS.="DateVal=LocalTime.valueOf();\n";
$JS.="LocalTime=new Date(DateVal+timediff*1000*60);\n";
$JS.="document.write( LocalTime.toLocaleString());\n";
$JS.="//--></script>\n";
return $JS;
}