1/ wxml代码
<view class="timePick"> <picker mode="date" fields="month" value="{{timestamp}}" start="1999-01-01" end="2999-12-12" bindchange="datePickerBindchange"> {{dateValue}} </picker> </view>
2/ js
data: { searchDate:"", timestamp:"" }, onLoad: function(options) { //日历默认值设置 this.timestamp=new Date().getTime() }, datePickerBindchange:function(e){ let date = e.detail.value+\'-01 00:00:00.0\'; date = date.substring(0,19); // date = date.replace(/-/g,\'/\'); let timestamp = new Date(date).getTime(); //插件再次打开时日期 let picktime=e.detail.value let timeString=picktime.replace(/-/g,\'年\')+\'月\'; // this.setData({ // dateValue:e.detail.value // }) this.setData({ searchDate:date, // searchDate:picktime, dateValue:timeString, //1019年12月 timestamp:picktime, }) }