微信小程序一周時間表功能實(shí)現(xiàn)
更新時間:2019年10月17日 10:47:59 作者:執(zhí)著的小前端
這篇文章主要介紹了微信小程序一周時間表功能實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
這篇文章主要介紹了微信小程序一周時間表功能實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
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(); //當(dāng)前年 this.nowMonth = this.now.getMonth(); //當(dāng)前月 this.nowDay = this.now.getDate(); //當(dāng)前日 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ù)(歷史紀(jì)錄) var timestamp = Date.parse(new Date(this.data.dateStart)); timestamp = timestamp / 1000; // console.log(timestamp); that.setData({ timestamp: timestamp }) }, // 點(diǎn)擊上一周 prevWeek: function(e) { this.data.num = this.data.num - 7; this.getWeekStartDate(this.data.num); }, // 點(diǎn)擊下一周 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(); //當(dāng)前年 this.nowMonth = this.now.getMonth(); //當(dāng)前月 this.nowDay = this.now.getDate(); //當(dāng)前日 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)); } //獲取本周的結(jié)束日期 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 }
效果如下
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
js 右鍵菜單,支持不同對象不同菜單(兼容IE、Firefox)
版本雖然很老也不符合標(biāo)準(zhǔn)了,不過代碼是值得參考的,需要右鍵菜單的朋友可以參考下。2010-01-01jscript之Open an Excel Spreadsheet
jscript之Open an Excel Spreadsheet...2007-06-06JavaScript實(shí)現(xiàn)預(yù)覽本地上傳圖片功能完整示例
這篇文章主要介紹了JavaScript實(shí)現(xiàn)預(yù)覽本地上傳圖片功能,結(jié)合完整實(shí)例形式分析了javascript圖片預(yù)覽相關(guān)的格式正則驗(yàn)證、瀏覽器判斷、頁面元素屬性動態(tài)操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2019-03-03JavaScript使用Math.random()生成簡單的驗(yàn)證碼
今天小編就為大家分享一篇關(guān)于JavaScript使用Math.random()生成簡單的驗(yàn)證碼,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2019-01-01