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= 1432365245

php time stamp generator to find the time stamp of any date

To display current time stamp we have to use time() function like this .

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() functino. Here is the code

echo date(" H:i:s", time());

The output is here 12:44:05

By using JavaScript we can display real time changing clock

Displaying current time & date by using localtime function in PHP

Here is the current time stamp again : 1432365245
From the value above let us display the current date and time by using the date function

echo date("m/d/y",time())

Here is the output showing current date and month value using the above  timestamp.


You can find detail php date today functions and php date formats in other tutorials in this section.

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 :

23/05/15 : 12:44:05

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 )

Solution: Server Clock using Ajax

Date Picker by using Calendar

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.

Number of User Comments : 41

Click for more tutorial on Date & Time functions and Applications

More On Date Object
Nice tutorial.
thanks, this tutorial really helped :)
I found what I have been looking for
really nice tutorial
Helped me a lot :)
Amol Bhavsar08-06-2009
Nice Article
thanks,excellent tutorial.
thanks it help me alot:)
Thanks this is the only code that actully displayed the current time.
nice tutorial...
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.tk31-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 ..
how to save my date in to my sql please, give tutor tq
manohar yadav15-02-2010
its realy very helpful for me..if is there any rating then i rate it to 80% fro javascript.
nice one
How to convert 3 text box value in a one variable in PHP
Ankit Tomar06-04-2010
Thanx for the tute specially for Time zone Asia/calcutta
amit chaudhary22-06-2010
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...
Masees Skenderian18-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?
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
Ernest Darling10-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 Narayanan29-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 Kefel22-05-2011
As a newbie php-user, this tutorial helped me a lot. Thanks
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! ;)
Great tutorial, Thanks
iqbal iqbal01-09-2012
great one
tnx bro... its really worked.....
Its very best way to practical success
Victor Olaru15-12-2012
Works perfectly, Thank you very much, Best regards
<?= 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)
You can use date_default_timezone_get() function to display time zone of the server
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();
alert(ctimeInSec.getUTCSeconds() );

Post Comment This is for short comments only. Use the forum for more discussions.

HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2015 All rights reserved worldwide Privacy Policy Disclaimer