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 convert time () value to year, month and day by php

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

Today, I would like to share with you how php converts the value of time () into the relevant knowledge points of the year, month and day. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article.

In php, you can use the date () function to transform, with the syntax "date (" Y-m-d ", time ())". The time () function can return a timestamp of the current time, while the date () function can format the timestamp with a format character (the value of the first parameter) to convert it to a date in the specified format.

Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

In php, the time () function is used to get the number of seconds of the current time since the Unix era (January 1 1970 00:00:00 GMT).

That is to return an integer containing the Unix timestamp of the current time.

So how do you convert the timestamp of the current time obtained by the time () function into a date in the format of year, month and day?

In PHP, you can use date () to do the transformation.

Date () can format the timestamp and convert it to a date in the specified format through the format character (the first parameter).

To convert the time () timestamp to the year, month and day format, the first parameter of date () needs to be controlled by the following characters:

The format string recognizes the string format character description of the following format parameters the day of the returned value example day-d month, the day of the month 01 to 31j with a leading zero, and the day of the month without a leading zero to 31 months, complete text format, such as the month represented by numbers from January or MarchJanuary to Decemberm Months represented by Jan to Decn digits with abbreviations from 0 01 to 12 m, without leading 0 1 to 12 years-Y4 digits are fully represented such as: 1999 or 2003y2 digits such as 99 or 03

The daily character combination of year and month is Y-m-d, and the output format is 2022-05-20.

Example:

The characters of year, month and day can be combined freely as needed:

This is all the content of the article "how php converts time () value to year, month and day". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

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