PHP Basic Knowledge Summary (4) Time function date

Source: Internet
Author: User
Tags echo date local time

one, Time ()-- returns the current Unix time Stamp

$nextWeek = time () + (7 * 24 * 60 * 60);

Echo ' Next Week: '. Date (' y-m-d ', $nextWeek). " \ n ";

Second, mktime ( hours/ minute/ sec/ month/ day/ year)-- get a date for Unix time Stamp

echo Date ("M-d-y", mktime (0, 0, 0, 12, 32, 1997)); jan-01-1998

echo Date ("M-d-y", mktime (0, 0, 0, 13, 1, 1997)); jan-01-1998

echo Date ("M-d-y", mktime (0, 0, 0, 1, 1, 1998)); jan-01-1998

echo Date ("M-d-y", mktime (0, 0, 0, 1, 1, 98)); jan-01-1998

Third, strtotime-- resolves a datetime description of any English text to Unix time Stamp

$time =time ();

Echo Strtotime ("Now"), "\ n";

Echo Strtotime ("Ten September"), "\ n";

Echo strtotime ("+1 Day",$time), "\ n";

Echo strtotime ("+1 Week",$time), "\ n";

Echo strtotime ("+1 Week 2 days 4 hours 2 Seconds",$time), "\ n";

Echo Strtotime ("Next Thursday",$time), "\ n";

Echo Strtotime ("Last Monday",$time), "\ n";

Iv. Date-- format a local time/date

1, year

Y--4 the year of the full representation of a digit, for example: 1999

Y--2 digit number of year, for example: 99

l--is a leap year, if it is a leap year of 1, otherwise 0

2, Month

m--three-letter abbreviation for month, Jan to Dec

m--number represents the month, with leading zeros, 01 to 12

f--month, January to December

n--number represents the month, without leading zeros, 1 to 12

t--number of days for a given month, 28 to 31

3, Japan

The day ordinal of the month in d--, with a leading zero of 2 digits, 01 to 31

s--suffix, 2 characters, st,nd,rd or th, after the number of days per month.

4, Week

d--Day of the week, text representation, 3 letters, Mon to Sun

L (Lowercase letter of "L")--days of the week, Sunday to Saturday

n--Day of the week, 1 (indicated Monday) to 7 (for Sunday)

w[lowercase]--Day of the week, number indicated, 0 (indicated Sunday) to 6 (for Saturday)

5.

Day of the z--year, 0 to 366

w[the week of the capital]--year, starting from Monday, for example: 42 (42nd Week of the year)

6. Time

a--lowercase morning and afternoon values, am or PM

a--uppercase morning and afternoon values, am or PM

g--hours, 12-hour format, no leading zeros

g--hours, 24-hour format, no leading zeros

h--hours, 12-hour format, with leading zeros

h--hours, 24-hour format, with leading zeros

i--number of minutes with leading zeros

s--number of seconds with leading zeros

7. Set the default time zone

Date_default_timezone_set (' UTC ');

Suppose today is: 2001.3.10, 5:16:18 pm

$today = Date ("F J, Y, g:i a"); March, 2001, 5:16 PM

$today = Date ("M.d.y"); 03.10.01

$today = Date ("J, N, Y"); 10, 3, 2001

$today = Date ("Ymd"); 20010310

$today = Date (' H-i-s, J-m-y, it's W day Z '); 05-16-17, 10-03-01, 1631 1618 6 Fripm01

$today = Date (' \i\t \i\s \t\h\e jS \d\a\y. '); It's the 10th day.

$today = Date ("D M J g:i:s T Y"); Sat Mar 15:16:08 MST 2001

$today = Date (' h:m:s \m \i\s\ \m\o\n\t\h '); 17:03:17 M is month

$today = Date ("H:i:s"); 17:16:17

Wu, getdate-- Get Date/time information

$today = getdate ();

Print_r ($today);

Array (

[Seconds] = 40

[Minutes] = 58

[Hours] = 21

[Mday] + 17//The number of days in the month indicated

[Wday] = 2//The number of days of the week represents 0 (for Sunday) to 6 (for Saturday)

[Mon] = 6/month number indication

[Year] = 2003

[Yday] = 167//The number of days of the year indicates

[Weekday] = Tuesday

[Month] = June

[0] = 1055901520

)

Gettimeofday--Get current time

Print_r (Gettimeofday ());

Array (

[sec] + 1073504408//number of seconds since the Unix era

[USEC] = 238215//microseconds

[Minuteswest] = 0//Greenwich Westward minutes

[Dsttime] + 1//Daylight saving time correction type

)

Echo Gettimeofday (TRUE);//1073504408.23910 returns a floating-point number when it is set to true.

Six, localtime-- Get local time

$localtime _assoc = localtime (Time (), true), or//If True, the index is represented by a number

Print_r ($localtime _ASSOC);

Array (

[Tm_sec] = 24//sec

[Tm_min] = 3//minutes

[Tm_hour] = 19/per hour

[Tm_mday] = 3//day of the month

[Tm_mon] = month of 3//year, starting from 0 for a month

[Tm_year] = 105//year, starting from 1900

[Tm_wday] = 0//day of the Week, from 0 (Sunday) to 6 (Saturday)

[Tm_yday] = 92//day of the year

[TM_ISDST] = 1//Daylight saving time is currently in effect

)

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.