note 82420 deleted from function.date by nlopess
| From: | nlopess@php.net | Date: | Sat, 12 Apr 2008 10:32:07 +0000 |
| Subject: | note 82420 deleted from function.date by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-138225@lists.php.net to get a copy of this message | ||
Note Submitter: coryking at mozimedia dot com
----
I've created a little web app to help test out how PHP will format your dates. It allows you
to paste in a date and time formatted in a variety of ways and uses this function to convert the
date to whatever you'd like. It was created because I find it hard to read ISO-8601 dates and
I also wanted a tool to "practice" how a date formatted in a certain way looks.
http://coryking.com/date-converter.php
The code does the formatting looks like this:
<?php
if(isset($_REQUEST['orig_time_zone'])) {
$origTimezone = new DateTimeZone($_REQUEST["orig_time_zone"]);
}else {
$origTimezone = new DateTimeZone("Europe/Warsaw");
}
$output = "";
if(isset($_REQUEST["date-field"]) && isset($_REQUEST['date-format'])
&& isset($_REQUEST['edited_user_timezone']) &&
isset($_REQUEST['orig_time_zone'])) {
$dt = new DateTime($_REQUEST["date-field"], $origTimezone);
$dt->setTimeZone(new DateTimeZone($_REQUEST['edited_user_timezone']));
}
?>
.... later on down the page...
<input name="result-string" id="result-string" readonly="readonly"
value="<?php if(isset($dt)) { echo $dt->format($_REQUEST['date-format']); }
?>" type="text" />