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
$currentTimeinSeconds = time();
echo $currentTimeinSeconds ;
?>
|
Output:
1525376494
Program 2: The program below prints the current time in date format.
<?php
$currentTimeinSeconds = time();
$currentDate = date ( 'Y-m-d' , $currentTimeinSeconds );
echo ( $currentDate );
?>
|
Output:
2018-05-03
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
05 May, 2018
Like Article
Save Article