Thursday, March 6, 2014

Tute 28 : Show Date and Time in Home Page : Part One

This tutorial we will show date and time in our website. We work only php script. We create a new file and include the file in index.php file.
So first we take a new document in notepad++ file. Write this code :


------------------------------------------------------------------
<?php
$time=time();

$modified_time= date('d/m/y H:i:s');

echo $modified_time;
?>
------------------------------------------------------------------------



here,
line 1: php starting code.
line 2: php time function
line 3 : We modified the core php time function. Basic time function not user friendly. So we modified the function.
line 4 : Publish the time.
and line 5 : ending php code.

Now save the file. We create a new folder in our "tute" directory. Our new folder name is : "require". Then save the file into "require" directory. We keep file name is : "datetime.inc.php"
After that we open google chrome and wirte this address in address bar and enter :
------------------------------------------------------
http://localhost/tute/require/datetime.inc.php
------------------------------------------------------
We see show a date and time. Here the date is today's date but time is wrong. Because This it is GMT time and date. So we modify this time for our country.



Again open the datetime.inc.php file in notepad++. Some edit the $modified_time= date('d/m/y H:i:s'); line. We replace this line:

-----------------------------------------------------------------
$modified_time= date('d/m/y H:i:s', $time+21600);
-----------------------------------------------------------------



Here, we make American time. As american time is less than 6 hour from GMT time so we minus 21600 (60s*60m*6h=21600) hour in server time.

Now go to Google chrome and refresh the datetime.inc.php tab. We see our time is changed.

If our country is Bangladesh we will plus 21600.
In Alaska we write : -32400
In Adelaide we write : +32430

No comments :

Post a Comment