当前位置:网站首页>Uniapp obtains the date implementation of the beginning and end of the previous month and the next month
Uniapp obtains the date implementation of the beginning and end of the previous month and the next month
2022-06-29 07:05:00 【A grain of procedural rice】



<template>
<view>
<button type="" @click="last()"> Last month </button>
<button type="" @click="next()"> Next month </button>
<view class="" >
{
{
startDate}}
</view>
<view class="">
{
{
endDate}}
</view>
</view>
</template>
<script>
export default {
data() {
return {
nowDate:"",
fullYear:"",
month:"",
endOfMonth:"",
endDate:"",
startDate:""
}
},
onReady() {
this.nowDate = new Date();
this.fullYear = this.nowDate.getFullYear();
this.month = this.nowDate.getMonth() + 1; // getMonth Method returns 0-11, representative 1-12 month
this.endOfMonth = new Date(this.fullYear, this.month, 0).getDate(); // Get the last day of the month
this.endDate = this.getFullDate(this.nowDate.setDate(this.endOfMonth));// The last day of the month
this.startDate = this.getFullDate(this.nowDate.setDate(1));// The first day of the month
},
methods: {
getFullDate(targetDate) {
var D, y, m, d;
if (targetDate) {
D = new Date(targetDate);
y = D.getFullYear();
m = D.getMonth() + 1;
d = D.getDate();
} else {
y = fullYear;
m = month;
d = date;
}
m = m > 9 ? m : '0' + m;
d = d > 9 ? d : '0' + d;
return y + '-' + m + '-' + d;
},
last(){
this.nowDate.setMonth(this.nowDate.getMonth()-1);
this.startDate = this.nowDate.getFullYear() + "-" + (this.nowDate.getMonth()+1) + "-" + this.nowDate.getDate()
this.endDate =this.getFullDate(new Date(this.nowDate.getFullYear(), this.nowDate.getMonth() + 1, 0))
},
next(){
this.nowDate.setMonth(this.nowDate.getMonth()+1);
this.startDate = this.nowDate.getFullYear() + "-" + (this.nowDate.getMonth()+1) + "-" + this.nowDate.getDate()
this.endDate =this.getFullDate(new Date(this.nowDate.getFullYear(), this.nowDate.getMonth() + 1, 0))
}
},
}
</script>
<style>
</style>
边栏推荐
猜你喜欢

Chapter V online logic analyzer signaltap

jetson tx2

IDEA 集成 码云

Message queue batch processing refund order through queue

作为一名合格的网工,你必须掌握的 DHCP Snooping 知识!

About DDNS

Illustrate plug-in -- AI plug-in development -- creative plug-in -- astute graphics -- length and angle measurement function

Service grid ASM year end summary: how do end users use the service grid?

Multimodal learning pooling with context gating for video classification

Unity AR Shadow 阴影
随机推荐
Summary of some new datasets proposed by cvpr2021
About DDNS
centos下配置mysql 5.7 和 8
C language pointer to function
. NETCORE uses redis to limit the number of interface accesses
Testing grpc service with grpcui
How to do the performance pressure test of "Health Code"
IDEA常用插件
Presto-Trial
Vite快速上手
Introduction to Ceres Quartet
Suggestions on digital transformation of large chemical enterprises
Configuring MySQL 5.7 and 8 under CentOS
NoSQL数据库之Redis(四):Redis新数据类型
Annual inventory review of Alibaba cloud's observable practices in 2021
解析学习幼儿机器人教育的浪潮
Redistemplate handles hash integer type problem resolution
It is the only one in China that Alibaba cloud container service has entered the Forrester leader quadrant
关于DDNS
Flutter is configured with a domestic image and connected to the real machine