note 69062 added to function.strftime

From: Date: Mon, 21 Aug 2006 23:05:33 +0000
Subject: note 69062 added to function.strftime
Groups: php.notes 
Request: Send a blank email to php-notes+get-116137@lists.php.net to get a copy of this message
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; } ---- Server IP: 83.138.144.80 Probable Submitter: 88.108.169.52 ---- X-Spam-Status: No, hits=3.7 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER, HTML_70_80,HTML_MESSAGE autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.strftime.php Edit -- https://master.php.net/note/edit/69062 Del: integrated -- https://master.php.net/note/delete/69062/integrated Del: useless -- https://master.php.net/note/delete/69062/useless Del: bad code -- https://master.php.net/note/delete/69062/bad+code Del: spam -- https://master.php.net/note/delete/69062/spam Del: non-english -- https://master.php.net/note/delete/69062/non-english Del: in docs -- https://master.php.net/note/delete/69062/in+docs Del: other reasons-- https://master.php.net/note/delete/69062 Reject -- https://master.php.net/note/reject/69062 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#116137) next »