Saturday 15 March 2014

Timestamps in php

timestamps in php
Timestamps in php programming language  Timestamps are widely used a standard used by php in order to keep track current time and current day in fact we had functions retrieve us current week and months the things like that. timestamps is numeric value or as integer value amount of second from the first of January 1970.

Code for time function (Screenshot1) :-

time function php
Time Function Screenshot1

<?php
echo time();
?>

Output (Screenshot 2,Screenshot3) :-

time function php
Screenshot2
time function php
Screenshot3
In this example time is function which echo out seconds from 1st January 1970 to today’s time seconds reached. Function returns current unit time stamps. As you can see output every time you refresh it will increase by seconds.So, its very useful to keep track of amount of second or current time depending upon you like if you want to track when the comment is posted when you posted on you post. But its not user-friendly because we are echoing the seconds not in human reader format.

Code for date and time function (Screenshot4):-

date and time function php
Screenshot4



<?php

$time = time();

$actual_time = date('H:i:s', $time);

echo 'The current time is '.$actual_time;

?>


Output (Screenshot5):-

date and time function php
Screenshot5
In this example i had created variable time with timestamp and we create actual_time in that we will process date function it takes two argument first how you want to display and we had key for different things to use second arguments here it is timestamp most common way to process first argument to display is H:i:s hour Minute and second. As you will see output it will be same time where in your system time i mean computer time. Timestamps updated dynamically.

Code for date and time function (Screenshot6):-

time date function php
Screenshot6


<?php

$time = time();

$actual_time = date('D M Y', $time);

echo 'The current time is '.$actual_time;

?>

Output (Screenshot7) :-

date time function in php
Screenshot7

In this example its a date month and year for current timestamps which is updating dynamically there are many other methods to get different formats of timestamps this are few examples from it.

Code for date and time function (Screenshot8):-

time date function in php
Screenshot8


<?php

$time = time();

$actual_time = date('D M Y @ H:i:s', $time);

echo 'The current date/time is '.$actual_time;

?>

Output (Screenshot9) :-

timestamps
Screenshot9


In this example its a current date month year and current time you have lot more its just few of them try your self.


No comments:

Post a Comment

Thanks For Comment Will get you Soon..

About Me

Welcome to Extra Tutorials! My name is Mohammed and I am the 22 year writer, website developer, and photographer behind the blog. Thanks for visiting! Tutorials Jackpot… In addition to Developer, I love to develop websites and I love to write. Starting a php Blog was inevitable for me. What began as a simple way to share all of my Tutorials with friends and family has developed into my Part time job.

Mohammed Padela

WHAT IS PHP PROGRAMMING

WHAT IS PHP PROGRAMMING
WHAT IS PHP PROGRAMMING

Follow Us

Popular Posts

Designed ByBlogger Templates