Name
time()
Synopsis
int time ( void )
PHP represents time as the number of seconds that have passed since January 1st 1970 00:00:00 GMT, a date known as the start of the Unix epoch; hence, this date format is known as epoch time or a Unix timestamp. This might be a peculiar way to store dates, but it works well—internally, you can store any date since 1970 as an integer, and convert to a human-readable string wherever necessary.
The basic function to get the current time in epoch format is time(). This takes no parameters and returns the current timestamp representing the current time on the server. Here is an example script:
print time();
$CurrentTime = time();
print $CurrentTime;As you can see, we can either print the return value of time() directly, or we can store it away in a variable and then print the contents of the variable—the result is identical.
Working in Unix time means you are not tied down to any specific formatting, which means you need not worry about whether your date has months before days (or vice versa), whether long months are used, whether day numbers or day words (Saturday, Tuesday, etc.) are used, and so on. Furthermore, to add one to a day (to get tomorrow's date), you can just add one day's worth of seconds to your current timestamp: 60×60×24 = 86400.
For more precise time values, use the microtime() function.