PHP Date Manipulation functions

Source: Internet
Author: User
Tags echo date idate julian day local time republican calendar sunrise time

<?php

Header (' content-type:text/html;charset=utf-8; ');

#总结php操作时间的函数

#1. Cal_days_in_month (calendar,month,year): function returns the number of days in one months for a specified year and calendar

#calendar: The calendar to be used, month: Specified month, year:

#calendar的可选参数为:

#CAL_GREGORIAN, Gregorian

#CAL_JULIAN, Caesar's calendar

#CAL_JEWISH, Jewish calendar

#CAL_FRENCH, the French Republican calendar

Echo ' 1.cal_days_in_month (calendar,month,year): ';

$d =cal_days_in_month (cal_gregorian,10,2005);

Echo ' <br> results: ';

Echo $d;


#2. CAL_FROM_JD (Jd,calendar): function converts the Julian day count to the date of the specified calendar

$d =unixtojd (Mktime (0,0,01,18,2006));

Echo ' <HR>2.CAL_FROM_JD: ';

Echo ' <br> results: ';

Print_r (Cal_from_jd ($d, Cal_gregorian));


#3. cal_info ([int $calendar =-1]): function returns an array containing information about the given calendar

Echo '

Print_r (cal_info (0));//Do not fill in the return of all calendar information, parameters set to 0,1,2,3 corresponding to the preceding calendar


#4. CAL_TO_JD (calender,month,day,year): function converts a specified date to a Julian date count

Echo '

$d =cal_to_jd (cal_gregorian,10,03,2005);

Echo $d;


#5. Easter_date (year): Returns the Unix timestamp for the Easter midnight of the specified years

#如果年份在Unix时间戳范围之外 (before 1970, or after 2037). This function generates a warning that you can use Easter_days instead of easter_date () to calculate Easter dates outside of the year

Echo '

$d =easter_date ();//year ellipsis represents the year

Echo $d;


#6. Easter_days () returns the number of days between the specified year and March 21

Echo '

$d =easter_days ();//year ellipsis represents the year

Echo $d;


#7. FRENCHTOJD () function converts the French Republican calendar into a Julian calendar;

The #GregorianToJD () function converts the Gregorian calendar to the Julian Calender method

Echo '

$JD = Gregoriantojd (10,3,1975);

Echo ($JD. "<br/>");


#8. Jddayofweek (Jd,mode): function return date in weeks

#mode可选, the optional value is: 0 default, returns the day of the week as an integer (0 for Sunday ...)

#1返回包含周的天的字符串.

#2. Returns a shortened string containing the days of the week

Echo '

$jd =cal_to_jd (Cal_gregorian,date ("M"), Date ("D"), Date ("Y"));

Echo (Jddayofweek ($JD, 1));


#9. Jdmonthname (Jd,mode): function returns the month string for the specified calendar

#mode可选, optional values:

#0, Gregorian calendar (abbreviated)

#1. Gregorian Calendar

#2. Caesar's Calendar (abbreviated)

#3. Caesar's Calendar

#4. Jewish Calendar

#5. French Republic Calendar

Echo '

$jd =cal_to_jd (cal_gregorian,date (' m '), date (' d '), date (' Y '));

Echo (Jdmonthname ($JD, 1));


10.JDToFrench (Juliandaycount): function converts the Julian day count to the Republic calendar

Jdtogregorian (Julianday): function converts the Julian day count to the Gregorian calendar

Jdtojewish (Juliandaycount): function converts the Julian day count to the Jewish calendar

Jdtojulian (Julianday): function converts Julian day count to Julian calendar

Jdtounix (Jday): function converts Julian day count to Unix timestamp

Echo '

$jd =gregoriantojd (10,3,1970);

$unix =jdtounix ($JD);

Echo $unix;


11.JewishToJD (month, day, year): function converts the Jewish calendar to a Julian day count

JULIANTOJD (month, day, year): function converts the Julian calendar into a Julian day count

UNIXTOJD (timestamp): function converts UNIX timestamp to Julian day count

Echo '

Echo Unixtojd ();


12.checkdate (month, day, year): function validation a Gregorian date

If the specified value is valid, the function returns True, otherwise it returns false

Month is between 1-12

Day is within the range of days that the specified month should have, and leap years are taken into account

Year between 1 and 32767

Echo '

Var_dump (Checkdate (12,31,2000));


13.date_default_timezone_get (OID): function returns the default time zone used by all DateTime functions in the script.

Date_default_timezone_set (Timezone_identifier): function set default time zone for all date/time functions in the script

Echo '

Echo Date_default_timezone_get ();


14.date_sunrise (Timestamp,format,latitude,longitude,zenith,gmt_offset): function returns the specified date and the sunrise time of the specified place

Date_sunset (Timestamp,format,latitude,longitude,zenith,gmt_offset): function returns the sunset time of the specified date and place

Format:sunfuncs_ret_string, returns the result in STRING format like 16:46

Sunfuncs_ret_double, returns the result in float format, such as 16.78243132

Sunfuncs_ret_timestamp, returns the result in the form of a timestamp

Latitude, the latitude of the specified location, in north latitude, default; negative, South latitude

Longitude, optional, longitude of the specified location. The default is longitude, if you want to specify West longitude, you need to pass a negative value

Zenith, optional

Gmt_offset, optional, specifies the difference between GMT and local time, in units of hours

Echo '

Echo (Date_sunrise (Time (), sunfuncs_ret_string,38.4,-9,90,1));

Echo date_sunrise (Time ());


15.date (format,timestamp): Format a local time/date

Echo '

echo Date (' y-m-d h:i:s ');

Echo ' <br> ';

echo Date (' y-m-d h:i:s ', Time ());


16.getdate (timestamp): Function acquisition date information

Returns the Mday, day of the month, Wday, day of the week in the result

Yday, Day of the year, 0, return timestamp

Echo '

Print_r (GETDATE ());


17.gettimeofday (): function returns an array containing the current time information

Returns the meaning of the array:

"SEC"-number of seconds since the Unix era

"USEC"-Number of microseconds

"Minuteswest"-the number of minutes to west of Greenwich

"Dsttime"-type of daylight saving time correction

Echo '

Echo (Gettimeofday (True). "<br/>");

Print_r (Gettimeofday ());


18.gmdate (Format,timestamp): Similar to date, returns Greenwich Mean Time

Echo '

echo gmdate (' y-m-d h:i:s ', Time ());


19.gmmktime (hour,minute,second,month,day,year): function gets unix timestamp for GMT date

Mktime ((hour,minute,second,month,day,year)): The function returns a Unix timestamp for a date.

Hour is optional. Specified hours.

Minute is optional. Specify minutes.

Second is optional. Specify seconds.

Month is optional. Specifies the number of months to be represented.

Day is optional. Prescribed days.

Year is optional. Prescribed year. On some systems, the legal value is between 1901-2038. However, there is no such limit in PHP 5.

Echo '

$d = Gmmktime (0,0,0,10,3,1975);

Echo $d;


20.gmstrftime (Format,timestamp): function formats GMT/UTC time/date according to local locale

Strftime (Format,timestamp): function formats local time/date based on locale

The two functions behave the same, but return different times, the former is Greenwich local time, the latter is local time

Echo '

Echo (Strftime ("%b%d%Y%x", Mktime (20,0,0,12,31,1998)));

Echo ' <br>strftime (format,timestamp):<br> ';

Echo (Gmstrftime ("%b%d%Y%x", Mktime (20,0,0,12,31,98)));


21.idate (Format,timestamp)://Format local time/date as an integer

Unlike date (), Idate () accepts only one character as the format parameter

The format parameter can have the following options:

B Swatch beat/internet Time

The day of the D-month

H Hours (12-hour format)

H hours (24-hour format)

I minute

I return 1 If daylight saving time is enabled, otherwise 0

L returns 1 if it is a leap year, otherwise 0

Number of the M-month

S number of seconds

T total number of days this month

U number of seconds since the Unix era (January 1 1970 00:00:00 GMT)-This works the same as time ()

The first day of the W Week (Sunday is 0)

The first week of the year in W ISO-8601 format, starting from Monday

Y year (1 or 2 digits – see instructions below)

Y year (4 digits)

The day ordinal of the Z-year

Z time zone offset in seconds

Echo '

echo idate (' Y ');


22.localtime (timestamp,is_associative): The function returns the local time (an array).

The different key names in the associative array are:

"Tm_sec"-Number of seconds

"Tm_min"-Number of minutes

"Tm_hour"-hours

"Tm_mday"-the day of the month

"Tm_mon"-the month ordinal of a year, starting from 0

"Tm_year"-year, starting from 1900

"Tm_wday"-the day of the week

"Tm_yday"-the day ordinal of a year

"TM_ISDST"-Daylight saving time is currently in effect

Echo '

$localtime = LocalTime ();

$localtime _assoc = localtime (Time (), true);

Print_r ($localtime);

Echo ' <br> ';

Print_r ($localtime _ASSOC);


23.microtime (): function returns current UNIX timestamp and subtle number

Echo '

Echo Microtime ();


24.STRTOTIMR (): function resolves datetime description of any English text to UNIX timestamp

Echo '

Echo strtotime (' Now ');

Echo ' <br> ';

echo strtotime (' 2014/7/22 ');


25.time (OID): Returns the Unix timestamp for the current time

Echo '

echo Time ();





?>


This article is from "Tiger Brother's Blog" blog, please be sure to keep this source http://7613577.blog.51cto.com/7603577/1531690

Related Article

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.