The most recent project is to write a client for a rest service, where the signature check needs to generate a date in RFC 1123 format in the HTTP header.
This problem is better solved, simply flip through the PHP document, using Gmstrftime This function can be solved.
Copy CodeThe code is as follows:
String Gmstrftime (string $format [, int $timestamp = time ()])
The code for the call is as follows:
Copy CodeThe code is as follows:
Echo Gmstrftime ("%a,%d%b%Y%T%Z", Time ());
Output: Tue, APR 16:16:07 GMT
During the commissioning process, it was found that on another computer, the output was not as expected, and then produced the Chinese:
Copy CodeThe code is as follows:
Two, 4 16:20:02 GMT
Continue to page through the document, find the note in the document, the result of this function is affected by the setlocale result, both the current system default language. Use the following command to view the languages that are currently installed on your system:
Copy CodeThe code is as follows:
Locale-a
Then, based on the results of the analysis just now, it is no problem to force the setlocale to be specified as English, the code is as follows:
Copy CodeThe code is 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 used on the Ubuntu machine, because it is live CD version, there is no en_us the language, but there is a en_us. UTF-8. This time the psychological drum, this practice seems not very safe, I can not determine whether to run the code on the client, whether there is en_US or en_US. UTF-8. Fortunately see a section of the document comments, can be replaced with gmdate, the function is not affected by the setlocale result:
Copy CodeThe code is 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.
http://www.bkjia.com/PHPjc/802222.html www.bkjia.com true http://www.bkjia.com/PHPjc/802222.html techarticle The most recent project is to write a client for a rest service, where the signature check needs to generate a date in RFC 1123 format in the HTTP header. This problem is better solved, simply skim the ph ...