This is a guide that you will not have an independent effect or document for the end of this month, but you will-hopefully-have an understanding of the U N IX timestamp and give you a powerful form of managing your P H p application.
Attention:
This guide expects the reader to understand how the MySQL database works and the basics of PHP
Unix time, or POSIX positive time, is a systematic description of the point in time. It is widely used not only for UNIX-like operating systems but also in many other computer systems, including the Java programming language. This is a coding for the coordinated world, and has enough similar linear representation over time, it is often a mistake.
Unix time is widely used in PHP. It amounts to seconds between January 1, 1970 00:00:00 (the Unix ERA) and this time to the nearest second place. As you can imagine, in the last 35 years, there are now quite a large number!
One of the things about Unix system time is to handle different Windows servers than the * nix servers. The time stamp on the Linux server can be positive or negative, equivalent to the UNIX era before and after. But the Windows Server produces-1, not a negative timestamp, or in PHP 5.1, it produces false.
PHP has many predefined functions that take advantage of the Unix time, functions that we will use including:
Date ()
Mktime ()
Strtotime ()
Time ()
The date () may be the most commonly used date feature in PHP, it can produce the current date or select the time in a large number of probabilities. All strings of the table are qualified here to
Mktime () has parameters, each setting time: Second, minute, hour, month, day and year. The seventh session parameter is based on daily savings but if this setting is left alone PHP will find the DS hour itself. Mktime () The speech that returns the timestamp parameter.
Strtotime () Converts a string to a timestamp, and if this cannot be done it will return-1 or false.
Time () returns the nearest second of the current time as a timestamp.
Scene
You have a form that enters data into the MySQL database including dates, in different pages you need to call back just one of your database columns.
Solution: As Unix time changes every second, they are almost unique in order to use, you can select a line of time stamp, for example:
-
- $sql = "SELECT * FROM data WHERE timestamp =" . Strtotime ("Sunday 3rd August 15:20:36");
-
- $result = mysql_query ($sql);
-
- $row = Mysql_fetch_assoc ($result);
-
- Echo "<pre>";
-
- Print_r ($row);
-
- Echo "</pre>";
-
-
-
This script queries the database table "data" to select all the rows the timestamp is the same time stamp of "Sunday August 3 15 o'clock 20 minutes 36 seconds." "The script then displays the array dollar row which is all the data retrieval queries.
This solves the problem because all the data is only one column is an array of dollars and can be output to the page at any time in a row. The disadvantage of this solution is that time is a very accurate, if the so-called date, or even the second time it will not select the correct data.
You have a cut-off date for a piece of work, and you want to know how many hours you have left.
Solution: You can use the Mktime feature to enter the date's expiration date and time stamp minus how much time is available to find out the current time.
-
- $day = 1;
-
- $month = one by one;
-
- $year = the same;
-
- $deadline = Mktime (', ', ', ', $month, $day, $year);
-
- $now = Time ();
-
- $age = $deadline - $now;
-
- $hours = Floor ($age * *);
-
- $age = $hours * ;
-
- Echo "Only $age days ($hours hours) left!";
-
-
This script obtains the current timestamp using the UNIX timestamp obtained by mktime () November 1, 2005 (The new cssreboot due date) and the time () function. Both are numbers, and within seconds we can block them. The result is a difference in the number of seconds, so multiply 60 to give you points, again 60-hour, and get 2 4 days.
You have the time and you need to show that as a format in different dates.
-
- Echo Date ("L DS of F Y",$timestamp);
-
- //produces something Like:monday 15th of August
-
-
-
- Echo Date ("R",$timestamp);
-
- //The RSS date format (RFC 2822)
-
- //Example:thu, Dec 16:01:07 +0200
-
-
-
- Echo Date ("M.d.y");
-
- Short-hand date:03.10.01
-
-
-
The date display feature changes countless times, and the current date and time stamp when added to the second parameter is the date format, not the one now. If you want to write the date feature such as "the" or "" character, you can show that the date format must be escaped. The full table date feature is available here.
That's it! I hope that if you follow this guide you learn some new PHP time, I hope you can use this new knowledge in your next PHP project