picker date模式不能选择今天以后的日期,出现1900 - 1 - 01
发布于 6 年前 作者 yongluo 4038 次浏览 来自 官方Issues

<view class='picker-container'>

  <picker mode='date' value='{{ picker.startDate }}' start='{{ startLimit }}' end='{{ picker.endDate }}' bindchange='getPickerValue' data-key='picker.startDate'>
    <view class='label fs-32 c-gray'><text>开始日期</text> {{ picker.startDate }}</view>
  </picker>
  <picker mode='date' value='{{ picker.endDate }}' start='{{ picker.startDate }}' bindchange='getPickerValue' data-key='picker.endDate'>
    <view class='label fs-32 c-gray'><text>结束日期</text> {{ picker.endDate }}</view>
  </picker>
</view>
const miment = require('miment')
 
Page({
    data: {
        picker: {
            startLimit: "",
            startDate: "",
            endDate: "",
            realEndDate: "",
        }
    },
 
    onload() {
        this.initPicker()
    },
 
    initPicker() {
        const FORMATER = 'YYYY-MM-DD'
        const today = new Date()
        const picker = {
            startLimit: miment(new Date(0)).format(FORMATER),
            startDate: miment(today.getFullYear(), today.getMonth() - 1, today.getDate()).format(FORMATER),
            endDate: miment(today.getFullYear(), today.getMonth(), today.getDate()).format(FORMATER),
        }
 
        if (new Date(picker.startLimit).getTime() > new Date(picker.startDate).getTime()) {
            picker.startDate = picker.startLimit
        }
        this.setData({
            picker
        })
    },
 
    getPickerValue(e) {
        const { key } = e.currentTarget.dataset
        this.setData({
            [key]: e.detail.value
        })
    },
}

渲染后的 wxml表现为

System: Android6.0.1

WeChat: 7.0.6 1460

WeChatLib: 2.8.0 (2019.8.8 20:04:12)

1 回复

你的end就是设置的当天呀

回到顶部