js: var time=new Date().toLocaleString();里面有中文 wxs var date=getDate(time); 不能识别 暂时的方法使用replace
wxs格式化出现的都是NAN,这是为什么?附代码这是wxml,content是测试数据库信息能否读出来 <wxs src="../../utils/util.wxs" module="util"></wxs> <view> {{util.msg}} </view> <view wx:for="{{txt_content}}"> <view class="time">{{util.timeFormat(item.creat_time)}}</view> <view class="text">{{item.content}}</view> </view> 这是util.wxs代码,msg测试是否能从wxs传过来 var timeFormat = function (time) { var date = getDate(time); var date_seconds = date.getTime() / 1000; var now = getDate(); var now_seconds = now.getTime() / 1000; var timestamp = now_seconds - date_seconds; var timeStr = ""; if (timestamp < 60) { timeStr = "刚刚"; } else if (timestamp >= 60 && timestamp < 60 * 60) { var minutes = parseInt(timestamp / 60); timeStr = minutes + "分钟前"; } else if (timestamp >= 60 * 60 && timestamp < 60 * 60 * 24) { var hours = parseInt(timestamp / 60 / 60); timeStr = hours + "小时前"; } else if (timestamp >= 60 * 60 * 24 && timestamp < 60 * 60 * 24 * 30) { var days = parseInt(timestamp / 60 / 60 / 24); timeStr = days + "天前"; } else { var year = date.getFullYear(); var month = date.getMonth(); var day = date.getDate(); var hour = date.getHours(); var minute = date.getMinutes(); timeStr = year + "/" + month + "/" + day + " " + hour + ":" + minute; } return timeStr; } module.exports = { timeFormat: timeFormat } module.exports.msg = "some msg"; 运行结果如图 [图片]有人知道这是怎么回事吗??
2021-10-01