In PHP we are going to use the timestamp conversion date can be implemented directly using the DATE function, if you want to convert the date to a timestamp can use the Strtotime () function implementation, let me give you an example.
1.php Time conversion function
Strtotime (datedate("Y-m-d h:i",$unixtime
Get the timestamp of today's 0 point in 2.php to get a Unix timestamp of 0 points, you can use
$todaytime=strtotime("Today"),
and then use
Date ("Y-m-d h:i",$todaytime)
Convert to a date.
Time Stamp converted to date
Timestamp conversion function:
Date ("Y-m-d h:i:s",Time ()), "Y-m-d H:i:s" is the converted date format, when() is the timestamp for the current time. If it is date ("y-m-d h:i:s", Time()), the hour and seconds are displayed together, and if it is a datetime(), only the month day is displayed. Example:date("Y-m-d h:i:s",Time ())
After the conversion:
Date ("y-m-d",Time ())
After the conversion:
The 2010-07-18 date is converted to a timestamp.
Class Saonekcontroller extends Controller {
Public Function Index
Action () {
/*
Time stamp conversion to date needless to say.
But the date is going to be a timestamp.
Strtotime ()
*/
$time = time ();//
Time stamp
$nowtime = Date (' y-m-d h:i:s ', $time);//
Create a formatted date
$oldtime = ' 2010-11-10 22:19:21 ';
$catime = Strtotime ($oldtime);//
Date converted to timestamp
$nowtimes = Date (' y-m-d h:i:s ', $catime);//
Time stamp is back to date.
Echo $nowtimes;
}
}
?>
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*/functionTranstime ($ustime) { $ytime=Date("Y-m-d h:i",$ustime); $rtime=Date("N-month J-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
Results:
2009-01-22 09:40:25
Specify time:
Echo Date ("Y-m-d h:i:s",strtotime
Results:
2009-01-23 09:40:25
(2) Print at the time of yesterday
Php
Time stamp
Strtotime
Current time:
Echo Date ("Y-m-d h:i:s", time
Results:
2009-01-22 09:40:25
Specify time:
Echo Date ("Y-m-d h:i:s",strtotime
Results:
2009-01-21 09:40:25
(3) Print the timestamp of the next week at this time
Strtotime
Current time:
Echo Date ("Y-m-d h:i:s", time
Results:
2009-01-22 09:40:25
Specify time:
Echo Date ("Y-m-d h:i:s",strtotime
Results:
2009-01-29 09:40:25
(4) Print the timestamp at the time of last week
Strtotime
Current time:
Echo Date ("Y-m-d h:i:s", time
Results:
2009-01-22 09:40:25
Specify time:
Echo Date ("Y-m-d h:i:s",strtotime
Results:
2009-01-15 09:40:25
(5) Print a PHP timestamp specifying the next day of the week
Strtotime ("Next
Current time:
Echo Date ("Y-m-d h:i:s", time
Results:
2009-01-22 09:40:25
Specify time:
Echo Date ("Y-m-d h:i:s",strtotime("Next
Results:
2009-01-29 00:00:00
(6) Print a timestamp specifying the last day of the week
Strtotime
Current time:
Echo Date ("Y-m-d h:i:s", time
Results:
2009-01-22 09:40:25
Specify time:
Echo Date ("Y-m-d h:i:s",strtotime
Results:
2009-01-15 00:00:00
Ext.: https://www.cnblogs.com/wang1204/p/5672846.html
PHP timestamp and date conversion (there is a problem with the text)