原创声明:本文为作者原创,未经允许不得转载,经授权转载需注明作者和出处
在一个功能上实现显示日期跟星期几,开发完后在开发工具上显示没问题,在安卓机上跑也没什么问题,但在IOS系统的苹果机上显示,时间跟星期几显示为NaN-NaN-NaN,求解
图:
贡上代码
wxml:
<view class="container">
<view class="top">
<view>{{weather.date}} {{weather.week}}</view>
<view>{{weather.city}}</view>
<!--<view>{{weather.updatedate}}</view>-->
</view>
</view>
js:
tempweather["date"] = utils.formatDate(basic["update"]["loc"]);
//当天日期
tempweather["week"]=utils.formatWeekdaybydate(basic["update"]["loc"]);
//周几
function formatDate(sdate) {
var vdate= new Date(sdate)
var year = vdate.getFullYear()
var month = vdate.getMonth() + 1
var day = vdate.getDate()
return [year, month, day].map(formatNumber).join('-')
}
function formatWeekdaybydate(sdate) {
var vdate = new Date(sdate);
var weekday = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
var index = vdate.getDay();
return weekday[index];
}