原創聲明:本文為作者原創,未經允許不得轉載,經授權轉載需注明作者和出處
在一個功能上實現顯示日期跟星期幾,開發完后在開發工具上顯示沒問題,在安卓機上跑也沒什么問題,但在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];
}