Sunday, August 21, 2011

Displays time with php

Belajar PHP

Php accompanied by a useful function to display information about the date and hour of the server at once, namely by using the function date(). (Note: function date() is not equal to several time zones).
date function syntax is as follows:

date("Y-m-d H:i:s"); 
 description:
  • Y = year;
  • m = months;
  • d = date;
  • H = hours;
  • i = min;
  • s = seconds;
 for example:
<?php
echo date("Y-m-d H:i:s");
?>
display the results were:
  • 2011-08-22 01:30:39
time on the show when the computer is:
  • 2011-08-22 00:30:39 
there is a difference of one hour. This is because the time is displayed by the php syntax is server time, not computer time.
Suppose your computer is set to GMT +7. So that the time displayed by the php with the time available on the client computer, then the php syntax becomes:
<?php
echo gmdate("Y-m-d H:i:s");
?>
So now php show time:
  •   2011-08-22 00:30:39
This is equivalent to the client computer.
You can also develop their own syntax, for example:
<?php
echo date("Y-m-d H:i:s"); # Waktu server Apache
echo ' – Server <br>';
echo gmdate("Y-m-d H:i:s"); #Waktu GMT
echo ' – GMT <br>';
echo gmdate("Y-m-d H:i:s", time()+60*60*7); # WIB
echo ' – WIB <br>';
?>
then try the syntax-the syntax above, what is happening. Good luck and be creative.
  

No comments:

Post a Comment