note 72384 added to ref.datetime
| From: | bgold at matrix-consultants dot com | Date: | Wed, 17 Jan 2007 01:08:09 +0000 |
| Subject: | note 72384 added to ref.datetime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-121823@lists.php.net to get a copy of this message | ||
When debugging code that stores date/time values in a database, you may find yourself wanting to
know the date/time that corresponds to a given unix timestamp, or the timestamp for a given date
& time.
The following script will do the conversion either way. If you give it a numeric timestamp, it will
display the corresponding date and time. If you give it a date and time (in almost any standard
format), it will display the timestamp.
All conversions are done for your locale/time zone.
<?
while (true)
{
// Read a line from standard in.
echo "enter time to convert: ";
$inline = fgets(STDIN);
$inline = trim($inline);
if ($inline == "" || $inline == ".")
break;
// See if the line is a date.
$pos = strpos($inline, "/");
if ($pos === false) {
// not a date, should be an integer.
$date = date("m/d/Y G:i:s", $inline);
echo "int2date: $inline -> $date\n";
} else {
$itime = strtotime($inline);
echo "date2int: $inline -> $itime\n";
}
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 64.17.250.94
----
Manual Page -- http://www.php.net/manual/en/ref.datetime.php
Edit -- https://master.php.net/note/edit/72384
Del: integrated -- https://master.php.net/note/delete/72384/integrated
Del: useless -- https://master.php.net/note/delete/72384/useless
Del: bad code -- https://master.php.net/note/delete/72384/bad+code
Del: spam -- https://master.php.net/note/delete/72384/spam
Del: non-english -- https://master.php.net/note/delete/72384/non-english
Del: in docs -- https://master.php.net/note/delete/72384/in+docs
Del: other reasons-- https://master.php.net/note/delete/72384
Reject -- https://master.php.net/note/reject/72384
Search -- https://master.php.net/manage/user-notes.php