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.
To display current time stamp we have to use time() function like this .
<?Php
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.
stamp.
Displaying current time
We can display current time by using time() function. Here is the code
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 :
02/04/23 : 11:59:36
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");
You can create two demo pages to understand concept of Time stamp.
Using html meta page refresh, create page which will reload itself at every 10 seconds and display the updated timestamp.
Try to display the timestamp in every 10 second duration without reloading the page. ( Use Ajax )
By using JavaScript we can display current month calendar and user can select a date from the calendar to input to a textbox. User can browse to different months of the calendar and select different dates.
User can also select two dates indicating Start date and end date.
Date picker by using JQuery
Jquery widget for calendar can be easily integrated to any website, you can set a range, disable dates and apply many other requirements easily.
Thanks this is the only code that actully displayed the current time.
ganesh
31-08-2009
nice tutorial...
sresti
08-11-2009
excellent tutorial and easy to read and easy to understand and more flexible to even beginers also..
Jarnail
24-11-2009
Thanks, Such a good tutorials. really help to convert time to date format
drmd - pmai.tk
31-12-2009
pretty interesting tutorial but i have a nota ..
while
# echo time() # displays current time-stamp,
# echo date("m/d/y",time()) # displays current time in the SERVER, e.g. her it s GMT - 6
so to display a GMT current time we have to add a sum of 6*60*60 to the time-stamp ..
burnquiss
29-01-2010
how to save my date in to my sql please, give tutor tq
manohar yadav
15-02-2010
its realy very helpful for me..if is there any rating then i rate it to 80% fro javascript.
harold
02-03-2010
nice one
Rahul
30-03-2010
How to convert 3 text box value in a one variable in PHP
Ankit Tomar
06-04-2010
Thanx for the tute specially for Time zone Asia/calcutta
amit chaudhary
22-06-2010
thanx for this nice tutorial,it is very helpful for me..
Pritesh
30-06-2010
yes its a very good tutoril all problems all easy solved thank you
Jahtex
29-08-2010
oh.. what a great tut... the mention of the php build in function date_default_timezone_set(); is a great revelation to my coding life.. once again many thanks to the writer...
Masees Skenderian
18-09-2010
iam using function: date("d/m/y : H:i:s", time())
how do i display the time in a 12 hours clock not a 24 hours clock?
smo
29-09-2010
Use small ( lower case ) h in place of upper case H. You can read more on date formats.
tiffin
02-11-2010
i am using function echo date("g:i");
But the time is early 4 hours from my pc time.How can i synchronize the time so that its the same as my pc time?
Amit
06-12-2010
How to use time stamp in cookies
Ernest Darling
10-01-2011
You are a life saver buddy but one more thing, How do I store a Timestamp into mysql database so it can later be retrieved as Timestamp?
Anantha Narayanan
29-04-2011
Hi, This was very helpful,
I have a doubt in mysql timezones and time-format, see i have a table in DB which has 2 important column which is location and timestamp, in which location can be anything, but i want the timestamp to be same format as it generated, since we have customers from different timezones, which i want the timestamp to be saved as it is, say if GMT it should saved as GMT, if it is pacific , it has to saved as PACIFIC,
Kinldy help me with your suggestions
Chris Kefel
22-05-2011
As a newbie php-user, this tutorial helped me a lot.
Thanks
tim
02-01-2012
Thanks for the tutorial.
My question is, if i have 2 events . How do l set the code to show the actual event each of the 2 events occured?
malekHaron
10-05-2012
thanks a lot bro! its really worked and its great! you sir, should be in the avengers! ;)
Jace
25-05-2012
Great tutorial,
Thanks
iqbal iqbal
01-09-2012
great one
amith
20-09-2012
tnx bro... its really worked.....
PREM
19-10-2012
Its very best way to practical success
Victor Olaru
15-12-2012
Works perfectly,
Thank you very much,
Best regards
rubab
03-04-2013
<?= date("D M d Y h:i:s a",time()); ?>
Every thing is perfect.the thing i want is now to display the time zone of server.Can anyone help me out.
its out put is:
Tue Apr 02 2013 07:32:06 pm (i want time zone to be displayed with this output)
Thx buddy.... The thing that I was looking for since long time.... Thx much...
Shaan
04-06-2014
How to add number of months to an current date
Bryan
12-07-2014
wow, thank you been trying to find out how to do this for ages, thanks a lot!
dnyanesh
24-12-2014
i want to convert timestamp in to seconds like below convert from date function.
anybody know any function to convert timestamps in seconds .
Thanks in advance !!!
var ctimeInSec = new Date();
alert(ctimeInSec.getUTCSeconds() );
mysql
06-07-2015
how can i display the current dynamic time without refreshing the current page
smo
09-07-2015
One way is using JavaScript to display clock from client side ( not server time ), you can check the tutorial on <a href=../javascript_tutorial/clock.php>dynamic clock</a>. There are links at end of the tutorial to show you how to collect server side time and display.
cedric
02-05-2016
You just solved a problem that i spent 3 days searching everywhere. Thanks a lot!
DAVISON PHIRI
08-11-2016
thinks for the time and date function, this function is really working but what am looking for is that: certain div part should refresh it safe after certain interval of the time.
demo
15-11-2016
You just solved a problem that i spent 3 days searching everywhere. Thanks a lot!