PHP implementation method to obtain the specified date is the day of the week, php day of the week

Source: Internet
Author: User

PHP implementation method to obtain the specified date is the day of the week, php day of the week

The example in this article describes how PHP can obtain the specified day of the week. We will share this with you for your reference. The details are as follows:

<? Php header ("Content-type: text/html; charset = UTF-8"); // obtain the week function get_week ($ date) {// force convert the date format $ date_str = date ('Y-m-d', strtotime ($ date )); // encapsulate it into an array $ arr = explode ("-", $ date_str); // parameter value assignment // year $ year = $ arr [0]; // month, the output is a two-digit integer with less than two digits aligned to the right. $ month = sprintf ('% 02d', $ arr [1]); // Day, the output is a two-digit integer, $ day = sprintf ('% 02d', $ arr [2]); // The default value of hour/second is 0; $ hour = $ minute = $ second = 0; // convert to timestamp $ hour = mktime ($ hour, $ minute, $ second, $ mon Th, $ day, $ year); // obtain the number of days of the week $ number_wk = date ("w", $ week ); // custom array of weeks $ weekArr = array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday "); // returns $ weekArr [$ number_wk];} // test $ date = "2016-08-20"; echo get_week ($ date); // Saturday?>

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.