- /*-------------------------------------------------------
- *
- * Copyright (c) 2011 Baidu.com, Inc. All Rights Reserved
- * $ Id $
- *
- *-------------------------------------------------------*/
- // Time stamp to date
- $ Date_time_array = getdate (1297845628); // 1311177600 1316865566
- $ Hours = $ date_time_array ["hours"];
- $ Minutes = $ date_time_array ["minutes"];
- $ Seconds = $ date_time_array ["seconds"];
- $ Month = $ date_time_array ["mon"];
- $ Day = $ date_time_array ["mday"];
- $ Year = $ date_time_array ["year"];
-
- Echo "year: $ year \ nmonth: $ month \ nday: $ day \ nhour: $ hours \ nminutes: $ minutes \ nseconds: $ seconds \ n ";
-
- // Normal date to timestamp
- Echo mktime (0, 0, 0, 9, 18,201 1). "\ n ";
- Echo mktime (0, 0, 0, 9, 25,201 1). "\ n ";
-
- /*
- Time ();
- Returns the current time, but returns an integer.
- */
- // You can format it.
- Echo "time () display Year Month Day hour minute second:". date ("Y-m-d H: I: s", time (). "\ n ";
- // Display in minutes
- Echo "time () shows only the year, month, and day:". date ("Y-m-d", time (). "\ n"; // only the year, month, and day are displayed.
- Echo "timestamp format:". date ("Y-m-d H: I: s", 1297845628). "\ n"; // use the timestamp directly.
// Convert a normal date to a timestamp. The same is true if there is a time, minute, and second,
- $ 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 );
/* Vim: set ts = 4 sw = 4 sts = 4 tw = 100 noet :*/
- ?>
Note: 1) There are two types of PHP Time difference: one is the timestamp type (1228348800) and the other is the normal date format) 2) the timestamp above php5.1 is 8 hours different from the actual time. the solution 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. Time zone identifier, available value in mainland China: PRC, Asia/Chongqing, Asia/Shanghai, Asia/Urumqi (China, Chongqing, Shanghai, Urumqi), Etc/GMT-8, asia/Harbin Hong Kong and Taiwan regions are available: Asia/Macao, Asia/Hong_Kong, Asia/Taipei (Macau, Hong Kong, and Taipei in sequence) and Singapore: asia/Singapore can be output in Beijing time. |