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 Screenshot1 |
<?php echo time(); ?>
Output (Screenshot 2,Screenshot3) :-
Screenshot2 |
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):-
Screenshot4 |
<?php $time = time(); $actual_time = date('H:i:s', $time); echo 'The current time is '.$actual_time; ?>
Output (Screenshot5):-
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):-
Screenshot6 |
<?php $time = time(); $actual_time = date('D M Y', $time); echo 'The current time is '.$actual_time; ?>
Output (Screenshot7) :-
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):-
Screenshot8 |
<?php $time = time(); $actual_time = date('D M Y @ H:i:s', $time); echo 'The current date/time is '.$actual_time; ?>
Output (Screenshot9) :-
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..