Mpvue 微信小程序:Android和IOS之间的兼容性,用于时间转换,下面就是今天南京小程序开发带来的文章解析。
Android和IOS在时间分辨率
1中有不同的分隔符.Android使用' - '来分割
2.IOS使用'/'来分段
在ios中使用新日期('2019-06-17'),返回null。IOS在时间格式解析中不知道' - ',需要用'/'代替; 海峡。在string方法中使用replace()方法。
String str。replace()方法
1. str。replace('要替换的字符串','新字符串')///此方法只能替换字符串中需要替换的第一个字符; 如果有任何想要替换的字符,则不会被替换。
2. str。replace(/要替换的字符串/ g,'新字符串')//使用正则表达式替换字符串中需要替换的所有字符(如果是' - ','/'等特殊字符,请记住添加'反斜杠'!)。
FormatDate (time) {// Accept parameter format XX xx-xx-xx
let newTime = '';
Let result ='; // receive time
Wx.getSystemInfo ({//Wechat widget to get device system information)
Success: function (res) {// Acquire system information successfully
if(res.platform == "devtools"){
Console. log ('I'm PC');
newTime = time;
}else if(res.platform == "ios"){
Console. log ('I'm IOS');
NewTime = time. replace (/-/g,'/'); when // system is IOS,'/'is used to segment.
}else if(res.platform == "android"){
Console. log ('I'm android');
newTime = time;
}
Let LR = new Date (new Time); // Past time of incoming
Let now = new Date (); // current time
let dt = now -lr;
Let second = DT / 1000; / seconds
if(second < 3600) {
Result = parseInt (s/60) +'minutes';
} else if(second < 86400) {
Result = parseInt (s/60/60) +'hour';
} Other if (second < 604800) {// within a week
Result = parseInt (s/60/60/24) +'day';
} else if(second <31104000) {
Result = parseInt (s/60/60/24/30) +'month';
} else if(second <311040000) {
Result = parseInt (s/60/60/24/30/12) +'year';
}
}, fail(err){
Console. log ('device system information acquisition failed', err)
},
})
return result
}
这是南京小程序开发安优网络在使用mpvue开发微信小程序时遇到的时间转换问题。我希望今天带来的文章是对你有所帮助。如果有什么我们可以在未来进行更多沟通。
本文地址:
http://www.njanyou.cn/web/2713.html
Tag:
专业服务:
南京网站制作,
南京网站制作公司,
南京网站建设公司
联系电话:025-65016872
上一篇:
南京网站制作认为:写作并没有死,你应该这样做
下一篇:
南京网站建设建立DIY网站前的3个问题(#2至关重要)