PHP getdate () function Get date information instance detailed

Source: Internet
Author: User
In PHP, there are several functions to get time and date, in addition to the time () function to get the current UNIX timestamp and using the DATE function to get the current time, you can also call the GETDATE () function to determine the current time, this chapter will introduce you to the "getdate ()" function.

Use of the GETDATE () function:

The GETDATE () function is the information that gets the specified part of the date specified, and its syntax is as follows:

GETDATE (timestamp);

The GETDATE () function returns the date and time information in the form of an array, if there is no parameter timestamp, whichever is the current time. The associated array element returned by the function is the following table:

The GETDATE () function returns an associative array element description

Key Name Description example of return value
"Seconds" The number of seconds is expressed 0 to
"Minutes" The number of minutes indicates 0 to
"Hours" The number of hours indicates 0 to
"Mday" The number of days in the month indicates 1 to
"Wday" The number of days of the week indicates 0(for Sunday) to 6(= Saturday)
"Mon" Numeric representation of the month 1 to
"Year" Full Year 4-digit representation Example:1999 or 2003
"Yday" The number of days in a year indicates 0 to 365
"Weekday" Full text representation of the day of the week Sunday to Saturday
"Month" Full text representation of the month january> to December
0 The number of seconds since the Unix era began, similar to the return value of Time () and the value used for date () . System-dependent, typical values are from -2147483648 to 2147483647.

getdate () function Example

Instance One

This example uses the GETDATE () function without parameters and the code is as follows:

<?php$time=getdate ();p rint_r ($time);? >

Running results such as:

The GETDATE () function returns date and time information as an array, so Print_r () is used to print.

Example Two

Use the GETDATE () function to get the current date information for the system and output the return value of the function, as shown in the example code:

<?phpheader ("Content-type:text/html;charset=utf-8");    Set the encoding $arr=getdate (); Echo $arr [year]. " -". $arr [Mon]." -". $arr [Mday]." "Echo $arr [hours].": "$arr [minutes].": ". $arr [seconds]." ". $arr [weekday]." <br/> "; echo" Today is the $arr [yday]th of year];? >

Running results such as:

Above is the simple application of our getdate () function.

We all know that one year 12 months, one weeks 7 days ..., but the computer is not known, so we have to check that the date is not valid, the next section, we will introduce the use of PHP functions to verify the validity of the date.

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.