The most recent project is to write a client for a rest service, where the signature checksum requires a date in RFC 1123 format to be generated in the HTTP header.
This problem is better solved, simply browsing through the PHP document, using Gmstrftime This function can be solved.
Copy Code code as follows:
String Gmstrftime (string $format [, int $timestamp = time ()])
The code to invoke is as follows:
Copy Code code as follows:
Echo Gmstrftime ("%a,%d%b%Y%T%Z", Time ());
Output: Tue, APR 2014 16:16:07 GMT
During the debugging process, it was found that on another computer the output was not as expected, and then the Chinese were produced:
Copy Code code as follows:
Continue browsing through the document, discovering the notes in the document, which are affected by the setlocale result, which is affected by the default language of the current system. Use the following command to view the languages that are installed on the current system:
Copy Code code as follows:
Then, based on the results of the analysis just analyzed, it is no problem to force the setlocale to be specified as English, the code is as follows:
Copy Code code as follows:
SetLocale (lc_time, ' en_US ');
Echo Gmstrftime ("%a,%d%b%Y%T%Z", Time ());
This article should have ended, but unfortunately the test on the Ubuntu machine, because it is the live CD version, there is no en_us the language, but there is a en_us. UTF-8. This time psychological drum, this practice seems not very safe, I have no way to determine the running code of the client, in the end there are en_US or en_US. UTF-8. It's good to see a piece of comments in a document that can be replaced with gmdate, which is not affected by setlocale results:
Copy Code code as follows:
Gmdate (' d, D M Y h:i:s '). ' GMT ';
Case closed~ Demand is small, it is not easy to write well, after more efforts.