JS package implementation based on the start time to calculate the current first few weeks

Source: Internet
Author: User
function Todayinfo (start,today) {var Weeklen = 7, weekdays = [' Day ', ' one ', ' Two ', ' three ', ' four ', ' five ', ' six ', Weekinfo = {' Week '  
        : null, ' Day ': null},//initialization return information, default NULL week, week null oneday = 24 * 60 * 60 * 1000,//milliseconds  Weekleave,///////The number of days remaining on the day of school Weekstart,//The start of the day is the week of DateDiff,//today and the date of the opening day sdate; On the day of school, date object var rdatestr =/\d{4}[\/-]\d{1,2}[\/-]\d{1,2}/g; Simple date format check: xxxx/xx/xx if (!rdatestr.test (start)) {alert (' Please use a valid start date ...
        ');
    return weekinfo;
    } sdate = new Date (Start.replace ('-', '/'));
    Weekstart = Sdate.getday (); Weekstart = Weekstart = = 0? 7:weekstart;
    JS Sunday index is 0, here to 7, to facilitate the calculation of Weekleave = Weeklen-weekstart; Today = new Date (today) | |
    New Date ();
    Weekinfo.day = Weekdays[today.getday ()]; Today = new Date (today.getfullyear () + '/' + (Today.getmonth () + 1) + '/' + today.getdate ());
    DateDiff = today-sdate; if (DateDiff < 0) {alert (start+ ') hasn't started yet.
        ');
    return weekinfo;
    } DateDiff = parseint (Datediff/oneday);
    Weekinfo.week = Math.ceil (datediff-weekleave)/Weeklen) + 1;
return weekinfo;
}//var td = Todayinfo (' 2017/3/1 '); ' First ' + Td.week + ' week, today's week ' + td.day;

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.