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.

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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
?>

chevron_right


Output:

1525376494

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

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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); 
?>

chevron_right


Output:

2018-05-03 


My Personal Notes arrow_drop_up

The function of education is to teach one to think intensively and to think critically

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.