| |
|
PHP TIME STAMP and DATE function |
PHP time stamp is a numeric value in seconds between the time at
present and the value at Unix Epoch
(January 1 1970 00:00:00 GMT). This time of January 1 1970 00:00:00
GMT is taken as base for all time stamp calculations. Below is the time
stamp or the number of seconds lapsed after January 1 1970 00:00:00 GMT and when
this page is loaded ( or opened by you). You can refresh this page to see the
current time stamp. Press the refresh button of your browser to reload this page
to see the current time stamp.
Current time stamp= 1211034379
You can use php time stamp generator to find the time stamp of any date, month, year with hour minute and seconds
In PHP the function giving the current
time stamp value is time(). So we can write a line like below to get the
current time stamp value.
<? echo time(); ?>
This line will print the value of
current time stamp as displayed at the top. Time stamp is used in many PHP
applications and from time stamp the current date and many different date format
can be taken by using different functions in PHP. We will display the time
stamp first and then use the code to display the current date from the time
stamp.
Here is the current time stamp : 1211034379
We used echo time() to display the
above line.
From the value above let us display the
current date and time by using the date function
echo date("m/d/y",time())
You can find detail php date today functions and php date formats in other tutorials in this section.Here is the current date and month
value using the above timestamp. 05/17/08
If you want to display the current time along with the date then change the format of the date function like this
date("d/m/y : H:i:s", time())
the out put of this will be like this : 17/05/08 : 09:26:19
Don't forget to refresh this page to see how the value changes.
Please note that the current date and time value displayed will be affected by default time zone set in your php.ini file of the server.
If you are testing this script in your local machine then take care of time zone setting in your php.ini file is set to your time zone.
You can change your time zone setting at your script page level by using this command
date_default_timezone_set ("Asia/Calcutta");
Or ( one more example )
date_default_timezone_set ("America/Denver");
|
|
| Subscribe |
|
Submit your email address and receive
article and product notifications. Your email is safe with us.
|
|
|
|
|
|