Get the date and time in PHP

Source: Internet
Author: User
Tags echo date time and date

PHP provides a variety of functions to get time and date, in addition to the time () function to get the current UNIX timestamp, call the GETDATE () function to determine the current time, through the Gettimeofday () function to get the specific time of day. In addition, the Date_sunrise () and date_sunset two functions can be used in PHP to get the sunrise and sunset time of a certain place.

   ① Call the GETDATE () function to get the date/time informationThe GETDATE () function returns a critical array of timestamps, and the parameters require an optional UNIX timestamp. If the timestamp is not given, it is considered the current local time.  Returns a total of 11 array elements, as shown in the following table. If you convert "October 1, 2009, 07:30:50 EDT" to Unix timestamp 1254382250, and pass it to the GETDATE () function, look at each array element as follows:
123456789101112131415 <?php  Array(  [seconds] => 50  [minutes] => 30  [hours] => 7  [mday] => 1  [wday] => 4            //一周中日的数值表示  [mon] => 10  [year] => 2009  [yday] => 273          //一年中日的数值表示  [weekday] => Thursday          //一周中日的完整文本表示  [month] => October             //月份的完整文本表示  [0] => 1254382250              //自从UNIX纪元开始至今的秒数  )?>
   ② Date and time formatted outputWhen a date and time need to be saved or calculated, the Unix timestamp should be used as a standard format, which can be an important rule. However, the UNIX timestamp format is poor in readability, so the timestamp is formatted as a more readable date and time, or as a format that is required by other software. In PHP, you can call the date () function to format a local time and date, and the prototype of the function is as follows: string date (string format[,int timestamp])//format a local time and date the function has two parameters, the first one The parameter is mandatory and specifies the time stamp for the conversion format. The second parameter is optional and needs to provide a Unix timestamp. Without this UNIX timestamp, the default value of time () returns the date and time of the current time. The function returns a string that is formatted to represent the appropriate date.             The common invocation method of the date () function is as follows: Echo date ("Y year M D Day H:i:s"); Output the current time format the first parameter in the date () function is a formatted string that consists of the specific characters provided in the following table. If the character in the formatted string is preceded by a backslash to escape, you can avoid it being interpreted as the following table. If the character after the backslash is a special sequence, then the backslash is also escaped. Characters that are not recognized in the format string are displayed as-is.  The following table shows the date format codes supported in PHP. The table contains all the formatting parameters that can be used with the data () function, which generates a string representation of the values specified by these parameters. To format dates for other languages, you should use the setlocale () and strftime () functions instead of date ().

>> This article fixed link: http://php.ncong.com/php_course/date/datetime.html

>> reprint Please specify: Ntshongwana PHP August 07, 2014 Yuncon PHP Learning tutorial Published

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.