Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vale1534/weeks
Get week numbers since January 1, 1970, get begin or other days in specified week.
https://github.com/vale1534/weeks
Last synced: 6 days ago
JSON representation
Get week numbers since January 1, 1970, get begin or other days in specified week.
- Host: GitHub
- URL: https://github.com/vale1534/weeks
- Owner: vale1534
- Created: 2017-07-05T08:18:54.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-07-05T08:24:16.000Z (over 7 years ago)
- Last Synced: 2023-10-29T21:42:50.203Z (about 1 year ago)
- Language: JavaScript
- Size: 27.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Weeks
## 怎么安装?
直接复制 `src/weeks.js` 文件,需要 ES6 支持。
## 什么功能?
计算某天是第几周,从 1970 年 1 月 1 日算起。
```js
import { weekOfDate } from 'weeks';// 计算某天是第几周
const today = new Date();
const theWeek = weekOfDate(today);
```反过来,计算某周的第一天和最后一天是哪天。默认以星期天为起始日,通过 `weeks.setStartOfWeek(1);` 设置以星期一为起始日。
```js
import { setStartOfWeek, firstDayOfWeek, lastDayOfWeek } from 'weeks';// 以星期一为起始日
setStartOfWeek(1);// 计算第 2048 周的星期一和星期日
const firstDay = firstDayOfWeek(2480);
const lastDay = lastDayOfWeek(2480);
```## 时区因素
**weeks** 默认使用当地时间计算第几周、第几天。也可通过 `weeks.setTimezoneOffsetMS()` 更改,具体请参考源码。