You can format a date in the desired format using the DateTime
class in PHP. Here's an example code snippet to format the date:
main.php458 chars15 lines
In this example, we first create a DateTime
object with the input date string and set the timezone to UTC. We then convert the timezone to the desired timezone (America/Los Angeles) using the setTimezone()
method. Finally, we format the date string into the desired format using the format()
method with the F j, Y g:i a
format string.
The F
format code stands for the full month name, j
stands for the day of the month without leading zeros, Y
stands for the four-digit year, g
stands for the hour in 12-hour format without leading zeros, i
stands for the minutes with leading zeros, and a
stands for the lowercase am/pm marker.
gistlibby LogSnag