Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to output English time and date by PHP

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "how to output English time and date in PHP". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to output English time and date in PHP".

In the recent project to write a client for a rest service, the signature verification needs to generate a Date in RFC 1123 format in HTTP Header.

This problem is easy to solve, simply flipping through the PHP documents, using gmstrftime this function can be solved.

The copy code is as follows:

String gmstrftime (string $format [, int $timestamp = time ()])

The code for the call is as follows:

The copy code is as follows:

Echo gmstrftime ("a, d, b Y T Z", time ())

/ / output: Tue, 01 Apr 2014 16:16:07 GMT

During debugging, it was found that on another computer, the output was not as expected, and then Chinese was produced:

The copy code is as follows:

2014 2014 16:20:02 GMT

Continue to flip through the document and find that it is stated in the comments that the result of this function is affected by the setlocale result, both by the default language of the current system. Use the following command to view the languages installed on the current system:

The copy code is as follows:

Locale-a

Then, according to the results of the analysis just now, it is no problem to specify setlocale as English. The code is as follows:

The copy code is as follows:

Setlocale (LC_TIME, 'en_US')

Echo gmstrftime ("a, d, b Y T Z", time ())

This article should be over by now, but unfortunately on the Ubuntu machine used for testing, because it is the Live CD version, there happens to be no en_US language, but there is an en_US.UTF-8. At this time, the psychological drum, this practice does not seem to be very safe, I am not sure whether there is an en_US or en_US.UTF-8 on the client running the code. Fortunately, you can see a section of comments in the document, which can be replaced by gmdate, which is not affected by the setlocale result:

The copy code is as follows:

Gmdate ('D, d M Y HizuiRu'). ' GMT'

Thank you for your reading. the above is the content of "how PHP outputs English time and date". After the study of this article, I believe you have a deeper understanding of how PHP outputs English time and date, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report