当前位置:网站首页>获取当前所在周的起始和结束的日期
获取当前所在周的起始和结束的日期
2022-06-22 20:50:00 【紫微前端】
/**
* 获取当前星期的起始日期和结束日期
* @param {string} startFormat 周一的时间格式
* @param {string} endFormat 周日的时间格式
* @param {number} timestamp 所在周的时间戳,若不传入,则默认使用当前时刻的时间戳
* @returns {string, string} {startDate, endDate} 返回的数据
*/
export const getWeekStartAndEnd = (
startFormat: string,
endFormat: string,
timestamp?: number
): {
startDate: string,
endDate: string,
} => {
const oneDayTime = 1000 * 3600 * 24;
const nowDate = timestamp ? new Date(timestamp) : new Date();
const now = nowDate.getTime();
const nowDay = nowDate.getDay() === 0 ? 7 : nowDate.getDay();
const startDate = new Date(now - oneDayTime * (nowDay - 1));
const endDate = new Date(now + oneDayTime * (7 - nowDay));
return {
startDate: formatTime(startDate.getTime(), startFormat),
endDate: formatTime(endDate.getTime(), endFormat),
};
};边栏推荐
- R language data Table data import practice: data Rename the name of the table data column (rename)
- 为 localStorage 添加过期时间
- c# sqlsugar,hisql,freesql orm框架全方位性能测试对比 sqlserver 性能测试
- Huawei cloud recruits partners in the field of industrial intelligence to provide strong support + commercial realization
- How to quickly build an enterprise knowledge base at low cost?
- 2021-08-21
- Which securities company is the safest and best choice for stock trading account opening
- Solve the problem that MySQL in phpstudy cannot be started and conflicts with locally installed MySQL
- Mysql database design
- 2020-12-04
猜你喜欢

Reinforcement learning weekly (issue 50): saferl kit, gmi-drl, rp-sdrl & offline meta reinforcement learning

The link added in the bottom menu cannot jump to the secondary page

2021-08-22

Experiment 4 operation comparison between NoSQL and relational database

In the third week of June, the main growth ranking list (BiliBili platform) of station B single feigua data up was released!

Remote access and control - SSH Remote Management and TCP wrappers access control

Generate detailed API and parameters of QR code using qrcodejs2

Developing salary management system based on C language course paper + source code and executable EXE file

How to continuously improve performance| DX R & D mode
Task cache compilation caused by gradle build cache
随机推荐
What are the indicators, dimensions and models in Business Intelligence BI data warehouse?
Mysql database DQL query operation
Considerations for using redisson to operate distributed queues
安装typescript环境并开启VSCode自动监视编译ts文件为js文件
c语言---17 函数简介
What if the SQL execution plan of the production system suddenly becomes worse?
Phantomjs实用代码段(持续更新中……)
Zynq ultrascale + rfsoc zcu111 RF clock tree learning 1
mysql主从同步及其分库分表基本流程
保证数据库和缓存的一致性
Solve the problem that MySQL in phpstudy cannot be started and conflicts with locally installed MySQL
Use full function simulation design method
2021-03-06
AutoCAD - five annotation shortcuts
Redis error reporting and common configurations
Task management of embedded development foundation (thread management)
How to manage tasks in note taking software such as flowus and notation?
Analysis of open API design specification
2020-12-20
A group of K overturned linked lists [disassembly / overturning / assembly of linked lists]