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