Therefore, there are two formats for saving the data to the database (more than my applications). The timestamp type is saved as a string, which is convenient.
The normal DATE type is saved as the DATE type.
Note that I usually use two types of PHP time. Therefore, the time type of the table created a few days ago is stored as DATE, and I keep saving it with a timestamp, the data is not written into the table all the time. After debugging for a long time, the error is that the data type does not match and is not written into the database.
The timestamp above is more convenient, but when it is displayed, we will not show this 1228348800 string to the customer, god nows!
The two transformations are used. First, let's talk about how to obtain the current timestamp, $ date1 = time (); so that the current timestamp is obtained, the date () function is used to convert back to the format. in PHP, the date () function is commonly used, such as obtaining the current date, you can use $ date2 = date ('Y-m-d');. Check the php manual if you do not understand the parameter.
Well, let's get down to the truth and convert 1228348800 to the format Code as follows:
$ Date3 = date ('Y-m-d H: I: s', "1228348800 ");
This is OK. If you still want to get the hour and minute, you only need to change 'Y-m-d'. But pay attention to it, PHP time seems to have an error of 8 hours. add OK.
The time stamp is converted to the normal date. Otherwise, convert the normal date format to the time stamp. See the following code:
$ Year = (int) substr ("",); // obtain the year
$ Month = (int) substr ("",); // obtain the month
$ Day = (int) substr ("",); // obtain the number of digits
Echo mktime (0, 0, 0, $ month, $ day, $ year );
In this way, the normal date can be converted into a timestamp. The same is true if there is a time, minute, and second,
Note: The time stamp above php5.1 is 8 hours different from the actual time. The specific solution of PHP time is as follows:
1. The simplest method is not to use php5.1 or a later version-obviously this is not an advisable method !!!
2. Modify php. ini. Open php. search for date in ini. remove the semicolon = Asia/Shanghai from timezone and restart the apache server. The disadvantage is that if the program is placed on another server, php cannot be modified. ini.
3. Add the initialization Statement of time to the program: "date_default_timezone_set (" Asia/Shanghai ");" which can be set by the programmer at will. I recommend this statement.
The Time Zone identifier. The available PHP time values in mainland China are PRC, Asia/Chongqing, Asia/Shanghai, Asia/Urumqi (China, Chongqing, Shanghai, and Urumqi in sequence ), GMT-8, Asia/Harbin Etc/
Available in Hong Kong and Taiwan regions: Asia/Macao, Asia/Hong_Kong, Asia/Taipei (in the order of Macao, Hong Kong, and Taipei)
Singapore: Asia/Singapore
Australia: Australia/sysydney