PHP/Development/Date Time
Содержание
Call system date function and get result
<?php
$result = shell_exec("date");
echo "<p>The server timestamp is: $result</p>";
?>
date: jS \o\f F Y, \a\\t g:ia \i\\n e
<?php
$time = time(); //stores the exact timestamp to use in this script
echo "Today is ";
echo date("jS \o\f F Y, \a\\t g:ia \i\\n e", $time);
?>
date: m/d/y G:i:s e
<?php
$time = time(); //stores the exact timestamp to use in this script
echo date("m/d/y G:i:s e", $time);
echo "<br/>";
?>
December 16th17AM.
<?
echo date ("F jS Y, h:iA.");
?>
Get date and time
<html><body>
<h1>Hello!</h1> <?
$dat=date("d.m y");
$tm=date("h:i:s");
echo "The current date is $dat<br>\n";
echo "The current time is $tm<br>\n";
?>
</body>
</html>
Save result of getdate() to an array
<?php
$date_array = getdate(); // no argument passed so today"s date will be used
foreach ($date_array as $key => $val) {
echo "$key = $val<br>";
}
?>
<hr/>
<?php
echo "<p>Today"s date: ".$date_array["mon"]."/".$date_array["mday"]."/".$date_array["year"]."</p>";
?>
String matches: /p.p/
<?php
$string = "PHP is great!";
$pattern = "/P.P/";
if(preg_match($pattern, $string))
print("Found a match!");
?>
String time
<?
print strftime ("%B %Z");
?>
Today"s Date
<html>
<head>
<title>Today"s Date</title>
</head>
<body>
<p>Today"s Date is
<?php
echo( date("l, F dS Y.") );
?></p>
</body>
</html>