This article will explain in detail how PHP formats local time and date into integers. The editor thinks it is quite practical, so I share it with you as a reference. I hope you will finish reading this article. You can gain something later.
PHP Format local time and date into integers
To format the local time date into an integer, you can use the strtotime() function of php
. This function converts the given datetime string to an integer in UNIX timestamp format representing the number of seconds elapsed since January 1, 1970 00:00:00 UTC.
grammar
int strtotime(string $timestamp)
parameter
return value
FALSE
is returned. usage
To format a local time date as an integer, use the following steps:
strtotime()
function. Example
// Get the current local time $datetime = date("Y-m-d H:i:s"); //Convert this to a UNIX timestamp $timestamp = strtotime($datetime); // Output UNIX timestamp echo $timestamp;
This example will output the number of seconds elapsed since January 1, 1970 00:00:00 UTC.
Notice
strtotime()
The function takes the local time zone. FALSE
. Other methods
In addition to the strtotime()
function, there are other methods to format local time and date into integers:
in conclusion
Use the strtotime()
function to easily format a local time date into an integer representing the number of seconds elapsed since January 1, 1970 00:00:00 UTC.
The above is the detailed content of PHP format local time date into integer. For more information, please follow other related articles on the PHP Chinese website!