https://github.com/liuyib/sunriset
🌄 Calculate sunrise and sunset times for a given date and location.
https://github.com/liuyib/sunriset
Last synced: 3 months ago
JSON representation
🌄 Calculate sunrise and sunset times for a given date and location.
- Host: GitHub
- URL: https://github.com/liuyib/sunriset
- Owner: liuyib
- License: mit
- Created: 2019-12-26T15:42:03.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-03-14T11:01:12.000Z (over 5 years ago)
- Last Synced: 2024-10-29T18:48:59.362Z (8 months ago)
- Language: JavaScript
- Homepage:
- Size: 43.9 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README-zh-Hans.md
- License: LICENSE
Awesome Lists containing this project
README
🌞 sunriset
通过日期和经纬度,计算日出和日落的时间。
[English](https://github.com/liuyib/sunriset/blob/master/README.md) | [简体中文](https://github.com/liuyib/sunriset/blob/master/README-zh-Hans.md)
## :cloud: 安装
```bash
# npm
npm install --save sunriset# yarn
yarn add sunriset
```也支持 CDN 引用:
```html
```
## :package: 使用
```js
import sunriset from 'sunriset';// Sunrise and sunset times of Beijing, December 27, 2019.
const longitude = 116.404;
const latitude = 39.908;const getSuntime = sunriset(new Date(), latitude, longitude);
// {
// sunrise: {
// raw_time: [7, 35],
// angle: 120.28914956738069,
// time: '07:35',
// formatted: '7:35, az = 120.28914956738069°',
// },
// sunset: {
// raw_time: [16, 56],
// angle: 239.73664214319098,
// time: '16:56',
// formatted: '16:56, az = 239.73664214319098°',
// },
// date: '2019-12-27T01:25:08.897Z',
// coordinates: [39.908, 0.32334444444444443],
// }
```## :memo: 文档
### `sunriset(date, lat, lon)`
通过日期和经纬度,计算日出和日落的时间。
#### 参数
- **Date** `date`: 日期
- **Number** `lat`: 维度
- **Number** `lon`: 经度#### 返回值
- **Object**:
- `sunrise` (Object):
- `raw_time` (Array): 一个数组,包含两个数字(小时和分钟)
- `time` (String): 格式化的日出时间(`HH:mm`)
- `sunset` (Object):
- `raw_time` (Array): 一个数组,包含两个数字(小时和分钟)
- `time` (String): 格式化的日落时间(`HH:mm`)
- `date` (Date): 输入的日期
- `coordinates` (Array): 输入的经纬度## :handshake: 开源协议
[MIT](https://github.com/liuyib/sunriset/blob/master/LICENSE) Copyright (c) 2019 [liuyib](https://github.com/liuyib/)