In PHP, you can get the current date and time using the date
function and the time
function.
To get the current date and time, you can use the following code:
main.php40 chars2 lines
The date
function formats the date and time according to the specified format, which in this case is Y-m-d H:i:s
. Y
represents the year, m
represents the month, d
represents the day, H
represents the hour in 24-hour format, i
represents the minute, and s
represents the second.
You can also get the current timestamp using the time
function, which returns the number of seconds since the Unix epoch (January 1 1970 00:00:00 GMT). To convert the timestamp to a readable date and time format, you can use the date
function:
main.php87 chars3 lines
This will give you the same result as the previous example.
gistlibby LogSnag