PHP Date and Time Flashcards
Q: What function is used to get the current timestamp in PHP?
A: time().
Q: What does the time() function return?
A: The current Unix timestamp (seconds since January 1, 1970).
Q: How do you format a date in PHP?
A: Use the date() function.
Q: What is the syntax of the date() function?
A: date(format, timestamp);.
Q: What is the default time zone in PHP?
A: It depends on the server configuration, often UTC.
Q: How do you format a date as “Year-Month-Day”?
A: date(‘Y-m-d’);.
Q: What does the format character d represent in the date() function?
A: Day of the month (01–31).
Q: What does the format character m represent in the date() function?
A: Numeric representation of a month (01–12).
Q: What does the format character Y represent in the date() function?
A: A four-digit year.
Q: What does the format character l represent in the date() function?
A: Full name of the day of the week (e.g., “Monday”).
Q: What does the format character H represent?
A: Hour in 24-hour format (00–23).
Q: What does the format character h represent?
A: Hour in 12-hour format (01–12).
Q: What does the format character i represent?
A: Minutes (00–59).
Q: What does the format character s represent?
A: Seconds (00–59).
Q: How do you display the current time as HH:MM:SS?
A: date(‘H:i:s’);.
Q: How do you set the default time zone in PHP?
A: date_default_timezone_set(‘timezone’);.