You can use the DateTime
class in PHP to format a date. Here's an example:
main.php95 chars5 lines
In this example, we create a new DateTime
object, which defaults to the current date and time. We then use the format
method to format the date in the desired format, which is 'yyyy-mm-dd hh:mm:ss'. The format string is passed as an argument to the format
method.
The H
format character is used for 24-hour time format, while the h
format character is used for 12-hour time format. The i
, s
, d
, m
, and Y
format characters are used for minutes, seconds, day, month, and year respectively.
The output of the example code will be something like this:
main.php20 chars2 lines
gistlibby LogSnag