Home > Web Front-end > JS Tutorial > body text

JavaScript calculates the day of the month in this year_time and date

WBOY
Release: 2016-05-16 18:55:08
Original
1594 people have browsed it
Copy code The code is as follows:

var getMonthWeek = function (a, b, c) {
/*
a = d = current date
b = 6 - w = how many days are left in the current week (not counting today)
The sum of a b divided by 7 means that today is the current month Week
*/
var date = new Date(a, parseInt(b) - 1, c), w = date.getDay(), d = date.getDate();
return Math .ceil(
(d 6 - w) / 7
);
};

var getYearWeek = function (a, b, c) {
/*
date1 is the current date
date2 is the first day of the current year
d is the current date’s day of the year
Use d to divide the sum of the week differences of the first day of the current year by 7 to get the day of the year Week
*/
var date1 = new Date(a, parseInt(b) - 1, c), date2 = new Date(a, 0, 1),
d = Math.round((date1 .valueOf() - date2.valueOf()) / 86400000);
return Math.ceil(
(d ((date2.getDay() 1) - 1)) / 7
);
};

document.write(
"Today is the month of the month", getMonthWeek(2007, 03, 19), "Week
"
, "Today is the ", getYearWeek(2007, 03, 19), "week"
);
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template