微信小程序--当前日期

功能:

显示当前日期

对应页面中的.js文件里添加

注意:

日期格式化函数不要写在Page({ … })里面

Page({
    onLoad: function(options) {
        // 日期
        var today = new Date;
        var solar = formatTime(today);
        let show_day = new Array('日', '一', '二', '三', '四', '五', '六');

        this.setData({
          solarCalendor: solar.year + '年' + solar.month + '月' + solar.day + '日 · 星期' + show_day[today.getDay()]
        })
    },
})

// 日期格式化函数
const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()

  return {
    year,
    month,
    day
  }
}

效果显示,可以去我的小程序看看效果哦,就在日历中。
《微信小程序--当前日期》

感觉有用的小伙伴,点个赞再走撒~

    原文作者:白话
    原文地址: https://blog.51cto.com/feature09/2492392
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞