網(wǎng)站首頁 編程語言 正文
page 因為我需要向接口里傳遞時間參數(shù),所以我在onLoad
里獲取
var that=this;
//今天
var time = util.formatData(new Date());
//昨天
that.getDateStr(null, -1); //獲取昨天的日期
that.getDateStrTwo(null, -2); //獲取前天的日期
that.getTimeLastWeek(7), //上周一的日期
that.getTimeLastWeek(1) //上周日的日期(一個星期的開始和結(jié)束日期)
自定義函數(shù)今天
就只有“今天”寫入在util.js里,只獲取年月日,格式為2020-03-11,module.exports需要調(diào)用
const formatData = date => {
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
return [year, month, day].map(formatNumber).join('-')
}
module.exports = {
formatData: formatData,
}
昨天和上月1號到上月本日
getDateStr: function (today, addDayCount) {
var date;
if (today) {
date = new Date(today);
} else {
date = new Date();
}
date.setDate(date.getDate() + addDayCount);//獲取AddDayCount天后的日期
var y = date.getFullYear();
var m = date.getMonth() + 1;//獲取當(dāng)前月份的日期
var d = date.getDate();
var up_m = date.getMonth(); //獲取上月
var up_d = 1; //獲取上月1號
var up_br = date.getDate() + 1; //上月本日
if (m < up_m) {
y = y - 1
}
if (m < 10) {
m = '0' + m;
};
if (up_m < 10) {
up_m = '0' + up_m;
};
if (d < 10) {
d = '0' + d;
};
if (up_d < 10) {
up_d = '0' + up_d;
};
if (up_br < 10) {
up_br = '0' + up_br;
};
this.setData({
yestodayStartTime: y + "-" + m + "-" + d,
yestodayEndTime:y + "-" + m + "-" + d,
up_monthStartTime: y + "-" + up_m + "-" + up_d,
up_monthEndTime: y + "-" + up_m + "-" + up_br,
})
//console.log(y + "-" + m + "-" + d)
return y + "-" + m + "-" + d;
},
前天
getDateStrTwo: function (today, addDayCount) {
var date;
if (today) {
date = new Date(today);
} else {
date = new Date();
}
date.setDate(date.getDate() + addDayCount);//獲取AddDayCount天后的日期
var y = date.getFullYear();
var m = date.getMonth() + 1;//獲取當(dāng)前月份的日期
var d = date.getDate();
if (m < 10) {
m = '0' + m;
};
if (d < 10) {
d = '0' + d;
};
this.setData({
twoBeforStartTime: y + "-" + m + "-" + d,
twoBeforEndTime: y + "-" + m + "-" + d,
})
//console.log(this.data.twoBeforStartTime);
return y + "-" + m + "-" + d;
},
上周(從周一到周日的日期)
getTimeLastWeek:function(n){
var now = new Date();
var year = now.getFullYear();
var month = now.getMonth() + 1;
var day = now.getDay(); //返回星期幾的某一天;
n = day == 0 ? n + 6 : n + (day - 1)
now.setDate(now.getDate() - n);
var date = now.getDate();
var s = year + "-" + (month < 10 ? ('0' + month) : month) + "-" + (date < 10 ? ('0' + date) : date);
return s;
}
})
原文鏈接:https://blog.csdn.net/Zan_Z/article/details/104800099
相關(guān)推薦
- 2022-05-29 Linux上使用Docker部署ASP.NET?Core應(yīng)用程序_實用技巧
- 2022-06-11 Python開發(fā)桌面小程序功能_python
- 2022-06-24 python包相關(guān)知識點之包的導(dǎo)入、相對路徑以及絕對路徑_python
- 2021-11-18 C/C++?Qt?TableDelegate?自定義代理組件使用詳解_C 語言
- 2022-10-23 C#中new操作符的工作機制_C#教程
- 2022-11-21 Go語言實現(xiàn)ssh&scp的方法詳解_Golang
- 2022-03-30 python批量修改xml文件中的信息_python
- 2022-08-12 Android自定義View實現(xiàn)圓形加載進度條_Android
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支