Php time and date functions-PHP source code

Source: Internet
Author: User
Tags echo date
Ec (2); setlocale () mktime () getdate obtains the time and date information. Syntax: arraygetdate (inttimestamp); Return Value: Array Function Type: time and date content description returned array elements include the following items: & quot; seconds & quot;-seconds & quot; minutes & quot;-minute & quot; hours & quot;-hour & quot; script ec (2); script

Setlocale () mktime ()
Getdate obtains the time and date information.
Syntax: array getdate (int timestamp );
Returned value: Array
Function Type: time and date
The returned array elements include the following items:
"Seconds"-seconds
"Minutes"-minute
"Hours"-hour
"Mday"-the day of the month
"Wday"-number of the day of the week
"Mon"-number of months
"Year"-year, number
"Yday"-the number of the day of the current year, for example, "299"
"Weekday"-Full name of the day of the week, for example, "Friday"
"Month"-Full name of the month, for example, "January"
Gettimeofday gets the current time.
Syntax: array gettimeofday (void );
Returned value: Array
Function Type: time and date
The returned array elements include the following items:
"Sec"-seconds
"Usec"-one minute per second
"Minuteswest"-Greenwich Mean Time score
"Dsttime"-destination time zone
Gmdate returns the time difference between the current time and GMT.
Syntax: string gmdate (string format, int timestamp );
Return Value: String
Function Type: time and date
This function is similar to the date () function. The difference is that this function returns the Time after the Time difference from the Greenwich Mean Time (GMT ).
Example
Echo date ("M d y h: I: s", mktime ));
Echo gmdate ("M d y h: I: s", mktime ));
?>
If the machine running this example is in Finland (Finland, GMT + 0200), the returned result is:
Jan 01 00:00:00 1998
Dec 31 1997 22:00:00
Refer to date () mktime () gmmktime ()
Easter_date is used to calculate the Easter date.
Syntax: int easter_date (int [year]);
Return Value: integer
Function Type: time and date
Description: if a year is input, the Easter date of the year is returned in UNIX time stamp format. If the year is not input, the date of the year is calculated. Value? Note that the input year must be between 1970 a.m. and 2037 a.m.; otherwise, it cannot be calculated.
Example
Echo date ("M-d-Y", easter_date (1999 ));
Echo date ("M-d-Y", easter_date (2000 ));
Echo date ("M-d-Y", easter_date (2001 ));
?>
The returned result is
Apr-04-1999
Apr-23-2000
Apr-15-2001
Easter_days is used to calculate the number of days between Easter and January 1, lunar March 21.
Syntax: int easter_days (int [year]);
Return Value: integer
Function Type: time and date
Description: if a year is input, the number of days between Easter and January 1, March 21 is calculated. If the year is not input, the current year is used. This function can be used to replace the issue that cannot be calculated beyond the range easter_date () 1970-2037.
Example
Echo easter_days (1999 );
Echo easter_days (1492 );
Echo easter_days (1913 );
?>
The returned result is:
14 (4/4)
32 (4/22)
2 (3/23)
Refer to easter_date ()
Mktime gets UNIX timestamps.
Syntax: int mktime (int hour, int minute, int second, int month, int day, int year );
Return Value: integer
Function Type: time and date
Description: enter a time to return a long integer of UNIX timestamps.
Example
Echo date ("M-d-Y", mktime ));
Echo date ("M-d-Y", mktime ));
Echo date ("M-d-Y", mktime ));
?>
Refer to date () time ()
Gmmktime obtains the Greenwich Mean Time of UNIX timestamps.
Syntax: int gmmktime (int hour, int minute, int second, int month, int day, int year );
Return Value: integer
Function Type: time and date
Description: enter a time to return a long integer of the UNIX Greenwich Mean Time Stamp.
Time gets the UNIX timestamp of the current time.
Syntax: int time (void );
Return Value: integer
Function Type: time and date
The content description returns the stamp value of the current time.
Refer to date ()
Microtime gets the UNIX timestamp value of one second per million at the current time.
Syntax: string microtime (void );
Return Value: String
Function Type: time and date
Description: returns the timestamp value of one million points per second of the current time. If the operating system does not provide the gettimeofday () System Call function, this function is also invalid.

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.