当前位置:首页 > 编程笔记 > 正文
已解决

javascript: weekOfYear 获取某天所处的一年中的周数

来自网友在路上 167867提问 提问时间:2023-10-28 09:38:46阅读次数: 67

最佳答案 问答题库678位专家为你答疑解惑

 /**
 * Get the number of week for a specific day in a year. It will return 1 to 53.
 */

// 方法 1
export function weekOfYear(year: number, month: number, day: number) {const startDate = new Date(year, 0, 1);const currentDate = new Date(year, month - 1, day);var days = Math.floor((currentDate.getTime() - startDate.getTime()) / (24 * 60 * 60 * 1000));return Math.ceil(days / 7);
}// 方法 2
import * as moment from 'moment';
export function weekOfMonth(year: number, month: number, day: number) {const date = new Date(year, month - 1, day);return parseInt(moment(date).format('W'));
}

查看全文

99%的人还看了

猜你感兴趣

版权申明

本文"javascript: weekOfYear 获取某天所处的一年中的周数":http://eshow365.cn/6-26685-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!