Example of php timestamp Conversion

Source: Internet
Author: User

The following example shows the result:
Copy codeThe Code is as follows:
Array (3) {["yesterday"] => array (2) {[0] => int (1395874800) [1] => int (1395961199 )} ["today"] => array (2) {[0] => int (1395961200) [1] => int (1396047599 )} ["tomorrow"] => array (2) {[0] => int (1396047600) [1] => int (1396133999 )}}

Copy codeThe Code is as follows:
<? Php

// Date Conversion Between Yesterday, Today and Tomorrow
// ($ Startstr start timestamp today)
// Return the values of and (yesterday, today, and tomorrow ).
Function alldaytostr ($ startstr ){
$ Oneday_count = 3600*24; // The number of seconds in a day
// Tomorrow
$ Tomorrow_s = $ startstr + $ oneday_count; // start tomorrow
$ Tomorrow_e = $ tomorrow_s + $ oneday_count-1; // end tomorrow
// Yesterday
$ Yesterday_s = $ startstr-$ oneday_count; // started yesterday
$ Yesterday_e = $ startstr-1; // ended yesterday
// End today
$ Today_e = $ tomorrow_s-1;
// Combine the values of yesterday, today, and tomorrow into an array
$ Allday_array = array ('yesterday' => array ($ yesterday_s, $ yesterday_e ),
'Today' => array ($ startstr, $ today_e ),
'Tomorrow' => array ($ tomorrow_s, $ tomorrow_e ));
Return $ allday_array;
}
// Start time of the current day
$ Btime = date ('Y-m-d'. '00: 00: 00', time ());
// Converts it to the start timestamp.
$ Btimestr = strtotime ($ btime );
Var_dump (alldaytostr ($ btimestr ));

?>

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.