Thursday, January 22, 2026
HomeLanguagesPHP | time() Function

PHP | time() Function

The time() function is a built-in function in PHP which returns the current time measured in the number of seconds since the Unix Epoch. The number of seconds can be converted to the current date using date() function in PHP.

Syntax:

int time()

Parameter: This function does not accepts any parameters as shown above.

Return Value: This function returns the current time measured in the number of seconds since the Unix Epoch.

Note: All output of programs corresponds to the date when the article was written.

Below programs illustrate the time() function:

Program 1: The program below prints the current time in term of seconds.




<?php
// PHP program to demonstrate the use of current 
// time in seconds since Unix Epoch 
  
// variable to store the current time in seconds 
$currentTimeinSeconds = time(); 
  
// prints the current time in seconds
echo $currentTimeinSeconds; 
?>


Output:

1525376494

Program 2: The program below prints the current time in date format.




<?php
// PHP program to demonstrate the use of current 
// date since Unix Epoch 
  
// variable to store the current time in seconds 
$currentTimeinSeconds = time(); 
  
// converts the time in seconds to current date 
$currentDate = date('Y-m-d', $currentTimeinSeconds);
  
// prints the current date
echo ($currentDate); 
?>


Output:

2018-05-03 
RELATED ARTICLES

Most Popular

Dominic
32475 POSTS0 COMMENTS
Milvus
119 POSTS0 COMMENTS
Nango Kala
6847 POSTS0 COMMENTS
Nicole Veronica
11977 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12064 POSTS0 COMMENTS
Shaida Kate Naidoo
6986 POSTS0 COMMENTS
Ted Musemwa
7220 POSTS0 COMMENTS
Thapelo Manthata
6933 POSTS0 COMMENTS
Umr Jansen
6912 POSTS0 COMMENTS