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 .
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.
Displaying current time
We can display current time by using time() functino. Here is the code
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
Or ( one more example )
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 )
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.
excellent tutorial and easy to read and easy to understand and more flexible to even beginers also..
Thanks, Such a good tutorials. really help to convert time to date format
drmd - pmai.tk
pretty interesting tutorial but i have a nota ..
# 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 ..
how to save my date in to my sql please, give tutor tq
How to convert 3 text box value in a one variable in PHP
Thanx for the tute specially for Time zone Asia/calcutta
thanx for this nice tutorial,it is very helpful for me..
yes its a very good tutoril all problems all easy solved thank you
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...
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?
Use small ( lower case ) h in place of upper case H. You can read more on date formats.
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?
How to use time stamp in cookies
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?
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
As a newbie php-user, this tutorial helped me a lot.
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?
thanks a lot bro! its really worked and its great! you sir, should be in the avengers! ;)
tnx bro... its really worked.....
Its very best way to practical success
Thank you very much,
<?= 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...
How to add number of months to an current date
wow, thank you been trying to find out how to do this for ages, thanks a lot!
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();
how can i display the current dynamic time without refreshing the current page