Quantcast
Viewing all articles
Browse latest Browse all 11

More Time and Dates in PHP!

Hi everyone!

Yesterday we began talking about writing out the date using PHP.
Today we will get to time. Before we learn how to write out the time using PHP, I will quickly show you how you can write out a copyright line at the bottom of your site, which will always be the most recent year. It’s actually quite simple!

All you have to do is insert the following line:

&copy; 2010-<?php echo date(“Y”)?>The output of this will be © 2010-2015

Easy as pie!

Now let’s move on to the time.

Just like we had some common characters for the date, bellow are some characters for time:

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 am or pm

You can also add in different characters to specify your format. For example, “/” “:” etc…

Take a look at the example below:

<?php
echo “The time is ” . date(“h:i:sa”);
?>

This will read – The time is 04:14:17pm

*Remember, the PHP date() function is getting the current date or time from the server!

Good luck practicing how to write the time using PHP!
See you next time!


Viewing all articles
Browse latest Browse all 11

Trending Articles