<title>php– Time function</title> php– time function Table of Contents
- Time
- Time format for date
- Time
- Date
- Mktime
- Strftime
- SetLocale
- Strtotime
- Datetime
- DateInterval
Time
/etc/php.ini
Date.timezone = Asia/shanghai
Date_default_timezone_set (' Asia/shanghai);
SetLocale (Lc_time, "C"); Echo strftime ("%y-%m-%d:%T"), ' <br> ';
Time format for date
Years:
Y: 4 digits y: 2 digits
Month:
F January to Decemberm 01 to 12n 1 to 12M Jan to Dec
Day:
D 01 to 31j 1 to 31
Week
D Mon to Sunj 1 to 31l Sunday to Saturdayn 1 to 7w 0 (representing Sunday) to 6
Hours:
H 24 h without leading 0 h has a leading 0 of 24 hours G without leading 0 12 hours G has a leading 0 of 12 hours a am, PmA am, PM
Minutes:
I have a leading 0
Seconds:
S has a leading 0
Milliseconds:
U MS number
Time
Time is 1970-01-01 from 00:00:00 to now the number of seconds elapsed
Time () # Unit is smicrotime () # Unit is smicrotime (1) # Unit is MS
Date
echo Date (' y-m-d h:i:s ');
echo Date (' y-m-d h:i:s ', Time ());
echo Date (' y-m-d h:i:s ', Filectime ($file));
Mktime
Mktime (H, I, S, M, D, Y)
Mktime (14, 23, 23, 07, 08, 1995)
echo Date (' y-m-d h:i:s ', mktime (0, 0, 0, 1, 1, 1970));
Strftime
Years:
%Y 4-bit%Y 2-bit
Month:
%b shorthand%b full write%m 00~12
Day:
%d 01到31% e 1 to 31
Week
%a shorthand%a Full write%u 1 to 7%w 0 to 6
Hours:
%H ~ 23%i ~ 12%l 1 ~ 12%p am, pm%p am, PM
Minutes:
%M 00 ~ 59
Seconds:
%s 00 ~ 59
Shorthand:
%F 2009-04-05%t 23:34:59
strftime
Usually setlocale
used together with
SetLocale
Lc_alllc_collatelc_ctypelc_monetary Monetary: Currency lc_numericlc_time
SetLocale (Lc_all, ' Zh_cn.utf8 '); Echo strftime ('%F%T '); Echo strftime ('%F%T ', Time ());
Strtotime
Strtotime (' 1 days '), Strtotime (' 1 day ');
Strtotime (' +45 days '), Strtotime (' -45 days ');
Strtotime ('-4 weeks '); Strtotime ('-4 week ');
Strtotime (' 4 weeks 2 days '), Strtotime ('-4 weeks-2 days ');
Datetime
$Raw=' 22. 11.1968. 16.52. ";$Start=DateTime:: Createfromformat (' d. M. Y. H. S ',$Raw);Echo ' Start Date: '.$Start-format(' y-m-d h:i:s ') ."<br>";$Start-setDate(2015, 8, 4);$Start-settime(19, 20, 00);Echo ' Current date: '.$Start-format(' y-m-d h:i:s ') ."<br>";$Start-Modify("+1days +24hours");Echo ' Current date: '.$Start-format(' y-m-d h:i:s ') ."<br>";
DateInterval
$time1=DateTime:: Createfromformat (' y-m-d h:i:s ',' 2015-08-10 12:00:20 ');// $time 1 = Datetime::createfromformat (' y-m-d h:i:s ', ' 2015-08-10 12:0:20 ');//ErrorEcho $time1-format(' y-m-d h:i:s '),' <br> ';$time2=DateTime:: Createfromformat (' y-m-d h:i:s ',' 2017-09-10 22:10:30 ');Echo $time2-format(' y-m-d h:i:s '),' <br> ';$span=$time2-diff($time1);// time2-time1Echo $span-format('%R ');Echo $span-format('%y-%m-%d: ');Echo $span-format('%h:%i:%s ');// -02-01-00:10:10:10$span=$time1-diff($time2);// time1-time2Echo $span-format('%R ');Echo $span-format('%y-%m-%d: ');Echo $span-format('%h:%i:%s ');// -02-01-00:10:10:10// Y indicates a leading 0// R "-" when negative, "+" when positive-, +// R "-" when negative, empty when positive-,
PHP--Time function