1. Time Format function date (Format,timestamp)
Format |
Time format |
Timestamp |
Time stamp |
Some of the characters commonly used in dates are listed below:
- D-Represents the day of the month (01-31)
- M-Denotes month (01-12)
- Y-Represents the year (four digits)
- 1-Indicates the day of the week
Other characters, such as "/", "." or "-" can also be inserted into characters to add additional formatting.
is the site version automatically updated? 2010-<?php echo Date ("Y")?>
2. Conversion between time stamp and time string
Timestamp function strtotime ()
Current timestamp time ()
Get a timestamp of 0 points today to get a Unix timestamp of 0 points, you can use
$todaytime =strtotime ("Today"),
and then use
Date ("Y-m-d h:i", $todaytime) is converted to a day.
If the date is to be converted into a timestamp, it will be used Strtotime ()
$oldtime = ' 2010-11-10 22:19:21 ';
$catime = Strtotime ($oldtime);
3.php timestamps are converted to dates and display different content by time, such as just, minutes ago, hours ago, today, yesterday, etc.
/*
Time conversion function
*/
function Transtime ($ustime) {
$ytime = Date ("y-m-d h:i", $ustime);
$rtime = Date ("M-D-Day h:i", $ustime);
$htime = Date ("H:i", $ustime);
$time = Time ()-$ustime;
$todaytime = Strtotime ("Today");
$time 1 = time ()-$todaytime;
if ($time < 60) {
$str = ' just ';
}else if ($time < 60 * 60) {
$min = Floor ($time/60);
$str = $min. ' Minutes ago ';
}else if ($time < $time 1) {
$str = ' Today '. $htime;
}else{
$str = $rtime;
}
return $str;
}
Other references
Use date to convert a timestamp to a specified timestamp into the system time
(1) Print the timestamp of the present time tomorrow
Strtotime ("+1 Day")
Current time:
echo Date ("Y-m-d h:i:s", Time ())
Specify time:
echo Date ("Y-m-d h:i:s", Strtotime ("+1 Day")
(2) Print at the time of yesterday
Time stamp
Strtotime ("-1 day")
Current time:
echo Date ("y-m-d h:i:s", Time ())
Specify time:
echo Date ("Y-m-d h:i:s", Strtotime ("1 day"))
(3) Print the timestamp of the next week at this time
Strtotime ("+1 Week")
Current time:
echo Date ("Y-m-d h:i:s", Time ())
Specify time:
echo Date ("Y-m-d h:i:s", Strtotime ("+1 Week"))
(4) Print the timestamp at the time of last week
Strtotime ("-1 Week")
Current time:
echo Date ("Y-m-d h:i:s", Time ())
Specify time:
echo Date ("Y-m-d h:i:s", Strtotime ("1 week"))
(5) Print a PHP timestamp specifying the next day of the week
Strtotime ("next Thursday")
Current time:
echo Date ("Y-m-d h:i:s", Time ())
Specify time:
echo Date ("Y-m-d h:i:s", Strtotime ("next Thursday"))
(6) Print a timestamp specifying the last day of the week
Strtotime ("last Thursday")
Current time:
echo Date ("Y-m-d h:i:s", Time ())
Specify time:
echo Date ("Y-m-d h:i:s", Strtotime ("last Thursday"))
(7) Print the timestamp specified last month
Strtotime ("-1 Months")
Current time:
echo Date ("Y-m-d h:i:s", Time ())
Specify time:
echo Date ("Y-m-d h:i:s", Strtotime ("1 Months"))
Attached examples:
<?php
echo
(
strtotime
(
"now"
));
echo
(
strtotime
(
"3 October 2017"
));
echo
(
strtotime
(
"+5 hours"
));
echo
(
strtotime
(
"+1 week"
));
echo
(
strtotime
(
"+1 week 3 days 7 hours 5 seconds"
));
echo
(
strtotime
(
"next Monday"
));
echo
(
strtotime
(
"last Sunday"
));
echo
date
(
"Y-m-d"
,
strtotime
(
"+1 months",
strtotime
(
"2018-5-1"
)));//下月一号
?>
php-Time function