Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

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()` 更改,具体请参考源码。