// //近一年的开始时间,具体日期
export function NearlyYearStart() {
let Year = new Date().getFullYear(); //获取完整的年份(4位)
let Month = new Date().getMonth() + 1; //获取当前月份(0-11,0代表1月)要加1
let day = new Date().getDate() //当前日期号
if (Month == '1') {
Month = Month
}else {
Month = Month
}
//给月份补零
if (Month < 10) {
Month = "0" + Month
}
// //给日期补零
if (day < 10) {
day = "0" + day
}
let ThisMonth = (Year - 1) + "-" + Month + "-" + day;
return ThisMonth
}
// //近一年的结束时间,具体日期
export function NearlyYearEnd() {
let Year = new Date().getFullYear(); //获取完整的年份(4位)
let Month = new Date().getMonth() + 1; //获取当前月份(0-11,0代表1月)要加1
let day = new Date().getDate() //当前日期号
let day2 = "";
console.log(Month)
// if (Month == '1') {
// Month = '12'
// Year = Year -1
// }else {
// Month = Month - 1
// Year = Year
// }
//获取当年2月的天数
var dayNum = new Date(Year,2,0).getDate();
console.log(Month)
console.log(dayNum)
//判断月份获取天数
// if (Month == "1") {
// day2 = 31
// }
// if (Month == "2") {
// day2 = dayNum
// }
// if (Month == "3") {
// day2 = 31
// }
// if (Month == "4") {
// day2 = 30
// }
// if (Month == "5") {
// day2 = 31
// }
// if (Month == "6") {
// day2 = 30
// }
// if (Month == "7") {
// day2 = 31
// }
// if (Month == "8") {
// day2 = 31
// }
// if (Month == "9") {
// day2 = 30
// }
// if (Month == "10") {
// day2 = 31
// }
// if (Month == "11") {
// day2 = 30
// }
// if (Month == "12") {
// day2 = 31
// }
//给月份补零
if (Month < 10) {
Month = "0" + Month
}
// //给日期补零
if (day-1 < 10) {
day = "0" + day
}
let ThisMonth = Year + "-" + Month + "-" + day;
return ThisMonth
}
// //近一月的开始时间,具体日期
export function NearlyMStart() {
let Year = new Date().getFullYear(); //获取完整的年份(4位)
let Month = new Date().getMonth() + 1; //获取当前月份(0-11,0代表1月)要加1
let day = new Date().getDate() //当前日期号
if (Month == '1') {
Month = Month
Year = Year - 1
}else {
Month = Month
}
//给月份补零
if (Month < 10) {
Month = "0" + Month
}
// //给日期补零
if (day < 10) {
day = "0" + day
}
let ThisMonth = Year + "-" + (Month-1) + "-" + day;
return ThisMonth
}
// //近一月的结束时间,具体日期
export function NearlyMStart2() {
let Year = new Date().getFullYear(); //获取完整的年份(4位)
let Month = new Date().getMonth() + 1; //获取当前月份(0-11,0代表1月)要加1
let day = new Date().getDate() //当前日期号
if (Month == '1') {
Month = Month
}else {
Month = Month
}
//给月份补零
if (Month < 10) {
Month = "0" + Month
}
// //给日期补零
if (day < 10) {
day = "0" + day
}
let ThisMonth = Year + "-" + Month + "-" + day;
return ThisMonth
}
// //近一周的开始时间,具体日期
export function NearlyWStart() {
// let Year = new Date().getFullYear(); //获取完整的年份(4位)
// let Month = new Date().getMonth() + 1; //获取当前月份(0-11,0代表1月)要加1
// let day = new Date().getDate() //当前日期号
// if (Month == '1' && day <= 7) {
// Year = Year - 1
// }
// console.log(142,day)
// if (day <= 7) {
// Month = Month - 1
// }
// //给月份补零
// if (Month < 10) {
// Month = "0" + Month
// }
// // //给日期补零
// if (day < 10) {
// day = "0" + day
// }
// console.log(142,Month)
// let ThisMonth = Year + "-" + Month + "-" + (day-7);
// console.log(142,ThisMonth)
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 7); //后7天就加7 获取的格式:Thu Jun 03 2021 10:38:40 GMT+0800 (中国标准时间)
console.log(187,start)
var newTime2 = start.toLocaleString(); //把日期转换成2018/6/4 下午10:45:19 格式
let resDate = start.getFullYear() + '-' + p((start.getMonth() + 1)) + '-' + p(start.getDate())
console.log(226,resDate)
return resDate
// return ThisMonth
}
// //近一周的结束时间,具体日期 也是药学监护的指标规则范围页面的开始日期(wardship-target-edit.vue)
export function NearlyWStart2() {
let Year = new Date().getFullYear(); //获取完整的年份(4位)
let Month = new Date().getMonth() + 1; //获取当前月份(0-11,0代表1月)要加1
let day = new Date().getDate() //当前日期号
if (Month == '1') {
Month = Month
}else {
Month = Month
}
//给月份补零
if (Month < 10) {
Month = "0" + Month
}
// //给日期补零
if (day < 10) {
day = "0" + day
}
let ThisMonth = Year + "-" + Month + "-" + day;
return ThisMonth
}
// 现在时间往后7天(一周)。学监护的指标规则范围页面的结束日期(wardship-target-edit.vue)
export function NearlyWStart3() {
let Year = new Date().getFullYear(); //获取完整的年份(4位)
let Month = new Date().getMonth() + 1; //获取当前月份(0-11,0代表1月)要加1
let day = new Date().getDate() //当前日期号
console.log(183,Month)
const start = new Date();
start.setTime(start.getTime() + 3600 * 1000 * 24 * 7); //后7天就加7 获取的格式:Thu Jun 03 2021 10:38:40 GMT+0800 (中国标准时间)
console.log(187,start)
//获取当年2月的天数
// var dayNum = new Date(Year,2,0).getDate();
// // console.log(193,dayNum)
// if (Month == '12' && day >= 25) {
// Year = Year + 1
// Month = 1
// }
// else if (Month == '1' || Month == '3' || Month == '5' || Month == '7' || Month == '8' || Month == '10' && day >= 25) {
// Month = Month + 1
// }
// else if (Month == '2' && dayNum == 28 && day >= 22) {
// Month = Month + 1
// }
// else if (Month == '2' && dayNum == 29 && day >= 23) {
// Month = Month + 1
// }
// else if (Month == '4' || Month == '6' || Month == '9' || Month == '11' && day >= 24) {
// console.log(201,Month)
// Month = Month + 1
// }
// console.log(142,day)
// if (day <= 7) {
// Month = Month - 1
// }
// //给月份补零
// if (Month < 10) {
// Month = "0" + Month
// }
// // //给日期补零
// if (day < 10) {
// day = "0" + day
// }
// console.log(142,Month)
// console.log(142,day)
// let day2 = day + 7
// let ThisMonth = Year + "-" + Month + "-" + day2;
var newTime2 = start.toLocaleString(); //把日期转换成2018/6/4 下午10:45:19 格式
let resDate = start.getFullYear() + '-' + p((start.getMonth() + 1)) + '-' + p(start.getDate())
console.log(226,resDate)
return resDate
}
//现在时间往前一个月的时间
export function NearMonth3() {
// let Year = new Date().getFullYear(); //获取完整的年份(4位)
// let Month = new Date().getMonth() + 1; //获取当前月份(0-11,0代表1月)要加1
// let day = new Date().getDate() //当前日期号
// console.log(183,Month)
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 30); //前30天就减30 获取的格式:Thu Jun 03 2021 10:38:40 GMT+0800 (中国标准时间)
console.log(245,start)
let resDate = start.getFullYear() + '-' + p((start.getMonth() + 1)) + '-' + p(start.getDate())
console.log(247,resDate)
return resDate
}
//现在时间往前一周的时间
export function NearWeek3() {
// let Year = new Date().getFullYear(); //获取完整的年份(4位)
// let Month = new Date().getMonth() + 1; //获取当前月份(0-11,0代表1月)要加1
// let day = new Date().getDate() //当前日期号
// console.log(183,Month)
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 7); //前7天就减7 获取的格式:Thu Jun 03 2021 10:38:40 GMT+0800 (中国标准时间)
console.log(245,start)
let resDate = start.getFullYear() + '-' + p((start.getMonth() + 1)) + '-' + p(start.getDate())
console.log(247,resDate)
return resDate
}
function p (s) {
return s < 10 ? '0' + s : s
};
// p:function (s) {
// return s < 10 ? '0' + s : s
// }
//当前时间: 年月日
export function getFullYearMonthDate() {
let Date2 = new Date().getFullYear(); //获取完整的年份(4位)
let Month = new Date().getMonth() + 1; //获取当前月份(0-11,0代表1月)要加1
let day = new Date().getDate() //当前日期号
//给月份补零
if (Month < 10) {
Month = "0" + Month
}
// //给日期补零
if (day < 10) {
day = "0" + day
}
let ThisMonth = Date2 + "-" + Month + "-" + day;
// console.log(283,ThisMonth)
return ThisMonth
}
要用到啥时间就取
在用的vue页面里
import { NearMonth3, NearWeek3 } from “@/api/time”;
然后this.startPlaceholder = NearMonth3();重新赋值就可;