PHP Development Time

Source: Internet
Author: User
1, get local timestamp
The PHP application Mktime () function converts a time to a Unix timestamp value. Timestamp is a long integer, including from the Unix era (January 1, 1070), a lot of time is based on this as the starting point, interested friends can search to see, there must be a story oh.
The syntax format for the mktime () function is as follows:
int mktime (int time,int minute,int second,int month,int day,int year,int [Is_dis])
The parameters of the Mktime () function are described in the following table:

2, get time and date

The current UNIX timestamp in PHP through the time () function. The syntax format is as follows:
int time (void)
The date () function in PHP is used to get the current time and date. The date () function is formatted as follows:
Date (string format,int timestamp)
About date format functions are shown in the following table:

The GETDATE () function is primarily used to obtain information about dates. The GETDATE () format is as follows:
Array getdate (int timestamp)
The returned array elements are shown in the following table:

The sample code is as follows:


    
     $array = getdate();echo$array['year']."-".$array['mon']."-".$array['mday'];?>

The results of the operation are as follows:

3, check the validity of the date
The validity of the check date is mainly implemented by the Checkdate () function, with the following syntax:
BOOL Checkdate (int month,int day,int year)
Let's implement it in code:


   
    $year =2011;$month =2;$day =31;echo var_dump(checkdate($day,$month,$year));?>

Running results:

4, output formatted time and date
This is done primarily through the date () function.
The format parameters are as follows:

5, first localized time and date

The localization of time and date is mainly achieved through the setlocale () function.
The specific syntax is as follows:
String setlocale (String category,string locale)
The options for the category of parameters are shown in the following table:

If the parameter locale is empty, the locale or Lang value of the system's variable is used, otherwise the localized environment specified by the locale is applied. such as en_US for the United States localization environment, CHS refers to Simplified Chinese, cht refers to traditional Chinese.

Strftime () function
The strftime () function formats the output time and date according to the localized environment
The syntax format is as follows:
String strftime (string format,int timestamp)



The sample code is as follows:


   
    setlocale(LC_ALL,"en_US");echo"美国格式:".strftime("Today is %A")."\n";setlocale(LC_ALL,"chs");echo"中文简体格式:".strftime("今天是:%A")."\n";setlocale(LC_ALL,"cht");echo"繁体中文格式:".strftime("今天是 :%A")."\n";?>

The results of the operation are as follows:

6, time and date resolved to UNIX timestamp
This is achieved primarily through the strtotime () function.
int Strtotime (string time,[,int time])
The function has two parameters, and if time is absolute, then the now parameter does not work. If the time parameter is in the form of a relative time, then the corresponding times are provided by now. If the now time is not provided, then the corresponding time is the current time. Returns false if parsing fails.
The sample code is as follows:


    EchoStrtotime ("Now")."\ n";//time stamp of the current timeEcho"Output time:". Date ("y-m-d h:i:s", Strtotime ("Now"))."\ n";//Output the current time according to the format requirementEchoStrtotime ("may")."\ n";//Output time stamp of the specified timeEcho"Output time:". Date ("y-m-d h:i:s", Strtotime ("may"))."\ n";//Output The time of the specified time in the formatEchoStrtotime ("+3 Day")."\ n";//Output three days after the timestampEcho"Output time:". Date ("y-m-d h:i:s", Strtotime ("+3 Day"))."\ n";//output in three days after the formatEchoStrtotime ("+1 Week")."\ n";//Output time stamp after one weekEcho"Output time:". Date ("y-m-d h:i:s", Strtotime ("+1 Week"))."\ n";//output in format after one weekEchoStrtotime ("+1 Week 2 days 3 hours 4 minutes")."\ n";EchoStrtotime ("Next week")."\ n";EchoStrtotime ("Last Monday")."\ n";?>

The results of the operation are as follows:

The above describes the PHP development time, including the aspects of the content, I hope the PHP tutorial interested in a friend helpful.

  • 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.