Weekly Data Processing

Source: Internet
Author: User
I. Time to week

This principle is relatively simple. Find the day of the week of the current week and the day of the month, then subtract, divide by the number of milliseconds of the week, and then add 1. The Code is as follows:

// Time to week: parameter (timestamp) function time2week (time) {var current = new date (time); var current_year = current. getfullyear (); var current_month = current. getmonth (); var current_date = current. getdate (); var current_week = current. getday (); var Thisyear = new date (current_year, 0, 1); // var thisyear_week = Thisyear on the first day of the year. getday (); var thisweek = new date (current_year, current_month, thisyear_week-current_week + current_date); // var cut = thisweek-Thisyear on the first day of the year; vaR week = cut/(1000*60*60*24*7) + 1; return week;} var timeline = 1410249135; alert (time2week (timeline * 1000 )); // 37
Ii. Weekly Data Transfer Time

This is a little more complex than above. First, determine the day of the first day of the year and the day of the second week of the year (because the Monday of the first week may be in the previous year ), determine the day of the week based on the number of weeks. The Code is as follows:

// Week conversion time: parameter (which week of the year, such as 201437) function week2date (STR) {STR = Str. tostring (); var res ={}; var year = Str. substring (0, 4); var week = Str. substring (4); var Thisyear = new date (year, 0, 1); var thisyear_week = Thisyear. getday (); // obtain Thisyear of week Week. setdate (parseint ("2876543 ". charat (thisyear_week) + (week-2) * 7); Res. start = {year: Thisyear. getfullyear (), month: Thisyear. getmonth () + 1, data: Thisyear. getdate ()}; // obtain Thisyear of the week Week. setdate (Thisyear. getdate () + 6); Res. end = {year: Thisyear. getfullyear (), month: Thisyear. getmonth () + 1, data: Thisyear. getdate ()}; return res;} console. log (week2date (201437); // object {start: object, end: Object} // start: Object/data: 8 // month: 9 // year: 2014 // end: Object // data: 14 // month: 9/year: 2014

 

Weekly Data Processing

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.