Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

Get a Time

Here are some commonly used characters for times:

  • H – 24-hour format of an hour (00 to 23)
  • h – 12-hour format of an hour with leading zeros (01 to 12)
  • i – Minutes with leading zeros (00 to 59)
  • s – Seconds with leading zeros (00 to 59)
  • a – Lowercase Ante meridiem and Post meridiem (am or pm)

The example below outputs the current time in the specified format:

Example

<?php
echo “The time is “ . date(“h:i:sa”);
?>
Keep in mind that the PHP date() function returns the current date and time of the server!