這期內容當中小編將會給大家?guī)碛嘘P微信小程序實現(xiàn)一周時間表功能,文章內容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供衡南網(wǎng)站建設、衡南做網(wǎng)站、衡南網(wǎng)站設計、衡南網(wǎng)站制作等企業(yè)網(wǎng)站建設、網(wǎng)頁設計與制作、衡南企業(yè)網(wǎng)站模板建站服務,十余年衡南做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡服務。
wxml
<view class="dateView"> <image class="dateLeft" bindtap="prevWeek" src="../../res/imgs/dateLeft.png"></image> <view>{{dateStart}} 至 {{dateEnd}}</view> <image class="dateRight" bindtap="nextWeek" src="../../res/imgs/dateRight.png"></image> </view>
wxss
.dateView{ padding:0 32rpx; height:98rpx; display: flex; align-items: center; background:#fff; } .dateView>image{ width:50rpx; height:50rpx; } .dateView>view{ flex: 1; text-align: center; color:#333; font-size: 34rpx; }
js
const GetPeriod = require("../../utils/getperiod.js"); Page({ /** * 頁面的初始數(shù)據(jù) */ data: { currentTab: 1, dateStart:'2019-10-16', dateEnd: '2019-10-16', }, /** * 生命周期函數(shù)--監(jiān)聽頁面加載 */ onLoad: function(options) { let that = this; that.getWeekStartDate(0) }, //獲取本周的開始日期 getWeekStartDate(numDay) { let that = this; this.now = new Date(); this.nowYear = this.now.getYear(); //當前年 this.nowMonth = this.now.getMonth(); //當前月 this.nowDay = this.now.getDate(); //當前日 this.nowDayOfWeek = this.now.getDay(); //今天是本周的第幾天 this.nowYear += (this.nowYear < 2000) ? 1900 : 0; let dateStart = GetPeriod.formatDate(new Date(this.nowYear, this.nowMonth, this.nowDay - this.nowDayOfWeek + 1 + numDay)); let dateEnd = GetPeriod.formatDate(new Date(this.nowYear, this.nowMonth, this.nowDay - this.nowDayOfWeek + 7 + numDay)); // console.log(dateStart) // 獲取今天日期 let now = GetPeriod.formatDate(new Date(this.nowYear, this.nowMonth, this.nowDay)); now = now.replace(/-/g, "/"); now = now.substring(5); this.setData({ dateStart: dateStart, dateEnd: dateEnd, now: now, dates: now, }) // 初始化數(shù)據(jù)(歷史紀錄) var timestamp = Date.parse(new Date(this.data.dateStart)); timestamp = timestamp / 1000; // console.log(timestamp); that.setData({ timestamp: timestamp }) }, // 點擊上一周 prevWeek: function(e) { this.data.num = this.data.num - 7; this.getWeekStartDate(this.data.num); }, // 點擊下一周 nextWeek: function(e) { this.data.num = this.data.num + 7; this.getWeekStartDate(this.data.num); }, })
function constructor1 (){ this.now = new Date(); this.nowYear = this.now.getYear(); //當前年 this.nowMonth = this.now.getMonth(); //當前月 this.nowDay = this.now.getDate(); //當前日 this.nowDayOfWeek = this.now.getDay(); //今天是本周的第幾天 this.nowYear += (this.nowYear < 2000) ? 1900 : 0; } //格式化數(shù)字 function formatNumber (n) { n = n.toString() return n[1] ? n : '0' + n } //格式化日期 function formatDate(date){ let myyear = date.getFullYear(); let mymonth = date.getMonth() + 1; let myweekday = date.getDate(); return [myyear, mymonth, myweekday].map(this.formatNumber).join('-'); } //獲取某月的天數(shù) function getMonthDays (myMonth) { let monthStartDate = new Date(this.nowYear, myMonth, 1); let monthEndDate = new Date(this.nowYear, myMonth + 1, 1); let days = (monthEndDate - monthStartDate) / (1000 * 60 * 60 * 24); return days; } //獲取本季度的開始月份 function getQuarterStartMonth (){ let startMonth = 0; if (this.nowMonth < 3) { startMonth = 0; } if (2 < this.nowMonth && this.nowMonth < 6) { startMonth = 3; } if (5 < this.nowMonth && this.nowMonth < 9) { startMonth = 6; } if (this.nowMonth > 8) { startMonth = 9; } return startMonth; } //獲取本周的開始日期 function getWeekStartDate() { return this.formatDate(new Date(this.nowYear, this.nowMonth, this.nowDay - this.nowDayOfWeek + 1)); } //獲取本周的結束日期 function getWeekEndDate() { return this.formatDate(new Date(this.nowYear, this.nowMonth, this.nowDay + (6 - this.nowDayOfWeek + 1))); } //獲取今天的日期 function getNowDate() { return this.formatDate(new Date(this.nowYear, this.nowMonth, this.nowDay)); } function formatTime(date) { var year = date.getFullYear() var month = date.getMonth() + 1 var day = date.getDate() var hour = date.getHours() var minute = date.getMinutes() var second = date.getSeconds() return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':') } module.exports = { formatNumber: formatNumber, constructor1: constructor1, formatDate: formatDate, getMonthDays: getMonthDays, getQuarterStartMonth: getQuarterStartMonth, getWeekStartDate: getWeekStartDate, getNowDate: getNowDate, getWeekEndDate: getWeekEndDate, formatTime: formatTime }
上述就是小編為大家分享的微信小程序實現(xiàn)一周時間表功能了,如果剛好有類似的疑惑,不妨參照上述分析進行理解。如果想知道更多相關知識,歡迎關注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
網(wǎng)頁題目:微信小程序實現(xiàn)一周時間表功能
鏈接URL:http://chinadenli.net/article6/gidgig.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供響應式網(wǎng)站、網(wǎng)站建設、手機網(wǎng)站建設、網(wǎng)站收錄、App設計、全網(wǎng)營銷推廣
聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)