A code _php tutorial that calculates the date and month of the day in PHP based on the first day of the year

Source: Internet
Author: User
This index value in addition to the instant Noodles data record and search, also plays the role of recording date information, the amount of information is considerable.
So, how do you restore the index value to the available date information?
Date (' Z ') returns the day ordinal of a year, and the return value is an integer starting from 0 to 365. To restore these integers to date information, we only need a simple calculation. Take the 159th day of this year (2008) (actually 160 days, PHP starting from 0, 0 for the first day of the routine) as an example, calculate its date, week method as follows:
Copy CodeThe code is as follows:
$MyDate = 159; 159th Day
$milliseconds = Mktime (0,0,0,1,1,2008) + $MyDate * 86400; Get Unix time stamp
$msg = Date (' F JS Y, l ', $milliseconds); Format Date Output
Echo $msg;
?>

Running the above program, the information displayed on the browser will be: June 8th, Sunday
Explanation:
I. $milliseconds is the UNIX timestamp variable, which indicates the number of milliseconds since the 159th day of 2008 from the time of the Unix era (January 1, 1700), which is an important basis for participating in the calculation of date information as a parameter in the date () function. To correctly calculate the value of $milliseconds, we first need to get the number of milliseconds experienced 2008 1st 1st, that is, Mktime (0,0,0,1,1,2008), and then add 159 days in milliseconds, that is, $MyDate * 86400, because, 86400 milliseconds per day.
Two. $msg is the date information we formatted the output, the value of this variable is obtained through the date () function, the first parameter "' F JS Y, L '" is only formatted format, can also be set to other, as needed, the second parameter is the number of milliseconds (Long integer type), The meaning is the total number of milliseconds that have elapsed from the beginning of the Unix period to a specific time.
To verify the correctness of the program, we can print the number of milliseconds experienced June 8, 2008: Mktime (0,0,0,6,8,2008), whose value will be the same as $milliseconds: 1212854400.

http://www.bkjia.com/PHPjc/322924.html www.bkjia.com true http://www.bkjia.com/PHPjc/322924.html techarticle This index value in addition to the instant Noodles data record and search, also plays the role of recording date information, the amount of information is considerable. So, how do you restore the index value to the available date information? Da ...

  • 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.