PHP Date chapter gives introduction to Timestamp initially and explains clearly about Time and Data Functions. Normally, Timestamp in UNIX will be the number of seconds that have been passed since January 1, 1970. Currently, the timestamp is 1467952558.But for every second, this time keep changing which increases the time number when the page is refreshed.
PHP date() function follows and formats the timestamp with high readability to give exact date and time.
Syntax
date(format,timestamp)
format - Specifies the format of the timestamp and is mandatory.
timestamp- Specifies a timestamp. it's default value is current date and time and is optional.
Characters used commonly:
d - denotes the day of the month (01 to 31)
m - denotes a month (01 to 12)
Y - denotes a year (in 4 digits)
l (lowercase 'L') - denotes the day of the week
Characters, like ., / or - also can be inserted in between the characters to add extra format to date() function.
The characters that are most commonly used for time are:
h - 12-hour format(01 to 12)
i - Minutes by including zeros (00 to 59)
s - Seconds by including zeros (00 to 59)
a - Lowercase Ante meridiem and Post meridiem (am or pm)
Example
[php]
<!DOCTYPE html>
<html>
<body>
<?php echo "The time is " . date("h:i:sa"); ?>
</body>
</html>
[/php]
Output:
Strtotime() Function
Description
The strtotime() function takes human readable language datetime description like English and converts it into a timestamp. By this,it is eady to determine "last Friday" or "past week" without the help of time() function and large math code.