mktime() 함수는 날짜의 Unix 타임스탬프를 반환합니다. Unix 타임스탬프에는 Unix epoch(1970년 1월 1일 00:00:00 GMT)와 지정된 시간 사이의 초 수가 포함됩니다.
구문:
mktime(시,분,초,월,일,년);
예:
<code><span><span><?php</span><span>$d</span> = mktime(<span>9</span>, <span>12</span>, <span>31</span>, <span>6</span>, <span>10</span>, <span>2015</span>); <span>echo</span><span>"创建日期是 "</span> . date(<span>"Y-m-d H:i:s"</span>, <span>$d</span>); <span>?></span></span></code>
공통 타임스탬프 함수
<code><span>/** * 得到开始和结束unix时间段 */</span> public function get_start_and_end_time(<span>$mark</span>) { <span>if</span>(<span>$mark</span> == <span>'yesterday'</span>) { <span>$start_time</span> = mktime(<span>0</span>,<span>0</span>,<span>0</span>,<span>date</span>(<span>'m'</span>),<span>date</span>(<span>'d'</span>) - <span>1</span>,<span>date</span>(<span>'Y'</span>)); <span>$end_time</span> = mktime(<span>0</span>,<span>0</span>,<span>0</span>,<span>date</span>(<span>'m'</span>),<span>date</span>(<span>'d'</span>),<span>date</span>(<span>'Y'</span>)) - <span>1</span>; }<span>else</span><span>if</span>(<span>$mark</span> == <span>'today'</span>) { <span>$start_time</span> = mktime(<span>0</span>,<span>0</span>,<span>0</span>,<span>date</span>(<span>'m'</span>),<span>date</span>(<span>'d'</span>),<span>date</span>(<span>'Y'</span>)); <span>$end_time</span> = mktime(<span>0</span>,<span>0</span>,<span>0</span>,<span>date</span>(<span>'m'</span>),<span>date</span>(<span>'d'</span>) + <span>1</span>,<span>date</span>(<span>'Y'</span>)) - <span>1</span>; }<span>else</span><span>if</span>(<span>$mark</span> == <span>'toweek'</span>) { <span>$start_time</span> = mktime(<span>0</span>,<span>0</span>,<span>0</span>,<span>date</span>(<span>'m'</span>),<span>date</span>(<span>'d'</span>) - <span>date</span>(<span>'w'</span>) + <span>1</span>,<span>date</span>(<span>'Y'</span>)); <span>$end_time</span> = mktime(<span>23</span>,<span>59</span>,<span>59</span>,<span>date</span>(<span>'m'</span>),<span>date</span>(<span>'d'</span>) - <span>date</span>(<span>'w'</span>) + <span>7</span>,<span>date</span>(<span>'Y'</span>)); }<span>else</span><span>if</span>(<span>$mark</span> == <span>'tomonth'</span>) { <span>$start_time</span> = mktime(<span>0</span>,<span>0</span>,<span>0</span>,<span>date</span>(<span>'m'</span>),<span>1</span>,<span>date</span>(<span>'Y'</span>)); <span>$end_time</span> = mktime(<span>23</span>,<span>59</span>,<span>59</span>,<span>date</span>(<span>'m'</span>),<span>date</span>(<span>'t'</span>),<span>date</span>(<span>'Y'</span>)); } <span>$arr</span>[<span>'start_time'</span>] = <span>$start_time</span>; <span>$arr</span>[<span>'end_time'</span>] = <span>$end_time</span>; <span>return</span><span>$arr</span>; }</code>
위 내용은 특정 시간의 타임스탬프를 가져오는 PHP와 관련 내용을 포함한 mktime() 함수를 소개하고 있어 PHP 튜토리얼에 관심이 있는 친구들에게 도움이 되기를 바랍니다.