How To Display The Current Time And Date On Web Pages Tutorial Guide PHP

Forums » PHP » How To Display The Current Time And Date On Web Pages Tutorial Guide PHP
This Page Contains information about How To Display The Current Time And Date On Web Pages Tutorial Guide PHP By webmaster with 3 Replies. Last Upated: Fri Apr 11, 2014
so you want to know how all those websites display the current date on their pages, well today you are in luck, i will show you how they do it.

One requirement is that you have PHP. If you are hosting your domain name with a web host, make sure you bought a PHP plan. If you don't have a PHP plan yet, you can purchase one by visiting www.webune.com they have great PHP plans for every level of deman you site needs. We recommend them to all our customers.

Once you know you have PHP, you will need to do this:

Tue Dec 05, 2006 2:34 pm
(weekday mothn day, year hour:minutes pm/am)

In my exaple here, i want to display the time and date in this format:

1. copy and paste the following code into your editor, you can use a simple text editor like notepad to creat php files. So copy and paste the following code into notepad:
CODE:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>PHP date() Function How To Display Time And Date Tutoril by Wallpaperama.com</title>
<style type="text/css">
<!--
.style1 {
   color: #FF0000;
   font-weight: bold;
}
.style3 {color: #0000FF}
.style4 {color: #CC0000}
-->
</style>
</head>

<body>
<h1 align="center">Display Time And Date Tutorial by <a href="http://www.wallpaperama.com">Wallpaperama</a> </h1> <hr />
<p align="center">PHP Hosting at <a href="http://www.webune.com">Webune.com</a> </p>
<p><br>
  <strong>The Current Time Is:</strong> <?php echo date("D M d, Y G:i a"); ?></p>
<p>This is the code I used to display the above date: <span class="style1">&lt;?php</span> <span class="style3">echo date(</span><span class="style4">&quot;D M d, Y G:i a&quot;</span><span class="style3">)</span>; <span class="style1">?&gt;</span><br>
</p>
<p align="left">&nbsp;</p>
<p align="left"><a href="http://www.wallpaperama.com/forums/how-to-display-the-current-time-and-date-on-web-pages-tutorial-guide-php-t564.html">&lt;&lt; Go back to Turorial </a></p>
<p align="center"><strong>USE THIS TABLE TO DISPLAY DATE DIFFERENT WAYS</strong></p>
<table width="768" border="1" align="center" cellpadding="5" cellspacing="0">
  <tr>
    <td width="102"><strong>format character</strong></td>
    <td width="487"><strong>Description</strong></td>
    <td width="269"><strong>Example returned values</strong></td>
  </tr>
  <tr>
    <td>Day</td>
    <td>---</td>
    <td>---</td>
  </tr>
  <tr>
    <td>d</td>
    <td>Day of the month, 2 digits with leading zeros</td>
    <td>01 to 31</td>
  </tr>
  <tr>
    <td>D</td>
    <td>A textual representation of a day, three letters</td>
    <td>Mon through Sun</td>
  </tr>
  <tr>
    <td>j</td>
    <td>Day of the month without leading zeros</td>
    <td>1 to 31</td>
  </tr>
  <tr>
    <td>l (lowercase 'L')</td>
    <td>A full textual representation of the day of the week</td>
    <td>Sunday through Saturday</td>
  </tr>
  <tr>
    <td>N</td>
    <td>ISO-8601 numeric representation of the day of the week (added in PHP 5.1.0)</td>
    <td>1 (for Monday) through 7 (for Sunday)</td>
  </tr>
  <tr>
    <td>S</td>
    <td>English ordinal suffix for the day of the month, 2 characters</td>
    <td>st, nd, rd or th. Works well with j</td>
  </tr>
  <tr>
    <td>w</td>
    <td>Numeric representation of the day of the week</td>
    <td>0 (for Sunday) through 6 (for Saturday)</td>
  </tr>
  <tr>
    <td>z</td>
    <td>The day of the year (starting from 0)</td>
    <td>0 through 365</td>
  </tr>
  <tr>
    <td>Week</td>
    <td>---</td>
    <td>---</td>
  </tr>
  <tr>
    <td>W</td>
    <td>ISO-8601 week number of year, weeks starting on Monday (added in PHP 4.1.0)</td>
    <td>Example: 42 (the 42nd week in the year)</td>
  </tr>
  <tr>
    <td>Month</td>
    <td>---</td>
    <td>---</td>
  </tr>
  <tr>
    <td>F</td>
    <td>A full textual representation of a month, such as January or March</td>
    <td>January through December</td>
  </tr>
  <tr>
    <td>m</td>
    <td>Numeric representation of a month, with leading zeros</td>
    <td>01 through 12</td>
  </tr>
  <tr>
    <td>M</td>
    <td>A short textual representation of a month, three letters</td>
    <td>Jan through Dec</td>
  </tr>
  <tr>
    <td>n</td>
    <td>Numeric representation of a month, without leading zeros</td>
    <td>1 through 12</td>
  </tr>
  <tr>
    <td>t</td>
    <td>Number of days in the given month</td>
    <td>28 through 31</td>
  </tr>
  <tr>
    <td>Year</td>
    <td>---</td>
    <td>---</td>
  </tr>
  <tr>
    <td>L</td>
    <td>Whether it's a leap year</td>
    <td>1 if it is a leap year, 0 otherwise.</td>
  </tr>
  <tr>
    <td>o</td>
    <td>ISO-8601 year number. This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead. (added in PHP 5.1.0)</td>
    <td>Examples: 1999 or 2003</td>
  </tr>
  <tr>
    <td>Y</td>
    <td>A full numeric representation of a year, 4 digits</td>
    <td>Examples: 1999 or 2003</td>
  </tr>
  <tr>
    <td>y</td>
    <td>A two digit representation of a year</td>
    <td>Examples: 99 or 03</td>
  </tr>
  <tr>
    <td>Time</td>
    <td>---</td>
    <td>---</td>
  </tr>
  <tr>
    <td>a</td>
    <td>Lowercase Ante meridiem and Post meridiem</td>
    <td>am or pm</td>
  </tr>
  <tr>
    <td>A</td>
    <td>Uppercase Ante meridiem and Post meridiem</td>
    <td>AM or PM</td>
  </tr>
  <tr>
    <td>B</td>
    <td>Swatch Internet time</td>
    <td>000 through 999</td>
  </tr>
  <tr>
    <td>g</td>
    <td>12-hour format of an hour without leading zeros</td>
    <td>1 through 12</td>
  </tr>
  <tr>
    <td>G</td>
    <td>24-hour format of an hour without leading zeros</td>
    <td>0 through 23</td>
  </tr>
  <tr>
    <td>h</td>
    <td>12-hour format of an hour with leading zeros</td>
    <td>01 through 12</td>
  </tr>
  <tr>
    <td>H</td>
    <td>24-hour format of an hour with leading zeros</td>
    <td>00 through 23</td>
  </tr>
  <tr>
    <td>i</td>
    <td>Minutes with leading zeros</td>
    <td>00 to 59</td>
  </tr>
  <tr>
    <td>s</td>
    <td>Seconds, with leading zeros</td>
    <td>00 through 59</td>
  </tr>
  <tr>
    <td>Timezone</td>
    <td>---</td>
    <td>---</td>
  </tr>
  <tr>
    <td>e</td>
    <td>Timezone identifier (added in PHP 5.1.0)</td>
    <td>Examples: UTC, GMT, Atlantic/Azores</td>
  </tr>
  <tr>
    <td>I (capital i)</td>
    <td>Whether or not the date is in daylight saving time</td>
    <td>1 if Daylight Saving Time, 0 otherwise.</td>
  </tr>
  <tr>
    <td>O</td>
    <td>Difference to Greenwich time (GMT) in hours</td>
    <td>Example: +0200</td>
  </tr>
  <tr>
    <td>P</td>
    <td>Difference to Greenwich time (GMT) with colon between hours and minutes (added in PHP 5.1.3)</td>
    <td>Example: +02:00</td>
  </tr>
  <tr>
    <td>T</td>
    <td>Timezone setting of this machine</td>
    <td>Examples: EST, MDT ...</td>
  </tr>
  <tr>
    <td>Z</td>
    <td>Timezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive.</td>
    <td>-43200 through 50400</td>
  </tr>
  <tr>
    <td>Full Date/Time</atd>
    <td>---</td>
    <td>---</td>
  </tr>
  <tr>
    <td>c</td>
    <td>ISO 8601 date (added in PHP 5)</td>
    <td>2004-02-12T15:19:21+00:00</td>
  </tr>
  <tr>
    <td>r</td>
    <td>RFC 2822 formatted date</td>
    <td>Example: Thu, 21 Dec 2000 16:01:07 +0200</td>
  </tr>
  <tr>
    <td>U</td>
    <td>Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)</td>
    <td>See also time()</td>
  </tr>
</table>

<p align="center">PHP Hosting at <a href="http://www.webune.com">Webune.com</a> </p>
</body>
</html>


2. once you have copied and pasted the code above into notepad, save it as time-and-date.php and upload to your web hosting site and open it with your browser.

3. When you open it with your browser, you will see a page displaying the current time,

4. If you don't have PHP yet, webune has provided us with space to help our visitors view our online tutorials.

[url=http://www.wallpaperama.com/tutorials/time-and-date.php]CLICK HERE TO SEE DEMO[/url] - Its exactly the same code as above



Hope this helps

Wallpaperama Team
Mike
cheers man that really helped, i have the date, time and swatch internet time on my site now lol

thanks!

mike, uk :)
http://wallpaperama.com/forums/how-to-display-the-current-time-and-date-on-web-pages-tutorial-guide-php-t564.html
no
ok seriously its nice and helpful but the time is displayed at GMT 0 and at the demo correctly. why dont you tell how to do that
sid
sorry budy but this code not work properly onto my machine
Title: How To Display The Current Time And Date On Web Pages Tutorial Guide PHP [988]
Tags: how to display the current time and date on web pages tutorial guide php