前言:
做微信小程序当中,会遇到好多的工具类util.js,这里记载下来以便平常使用 (Ps:建议通过目录查看)
-获取日期(格式化)
function formatTime(date) { var year = date.getFullYear() var month = date.getMonth() + 1 var day = date.getDate()return [year, month, day].map(formatNumber).join( #39;/ #39;) + #39; #39; + [hour, minute, second].map(formatNumber).join( #39;: #39;)
return n[1] ? n : #39;0 #39; + n }
-获取动态更新时间
function getDateDiff (dateTimeStamp) { var minute = 1000 * 60; var hour = minute * 60; var day = hour * 24; var halfamonth = day * 15; var month = day * 30; var year = day * 365; var now = new Date().getTime(); var diffValue = now - dateTimeStamp; if(diffValue 0){ //非法操作 return #39;数据出错 #39;; var yearC = diffValue / year; var monthC = diffValue / month; var weekC = diffValue / (7 * day); var dayC = diffValue / day; var hourC = diffValue / hour; var minC = diffValue / minute; if(yearC = 1){ result = parseInt(yearC) + #39;年以前 #39;; }else if(monthC = 1){ result = parseInt(monthC) + #39;个月前 #39;; }else if(weekC = 1){ result = parseInt(weekC) + #39;星期前 #39;; }else if(dayC = 1){ result = parseInt(dayC) + #39;天前 #39;; }else if(hourC = 1){ result = parseInt(hourC) + #39;小时前 #39;; }else if(minC = 5){ result = parseInt(minC) + #39;分钟前 #39;; }else{ result = #39;刚刚发表 #39;; return result; }
以上就是微信小程序开发中常用工具类的实例详解的详细内容,更多请关注php中文网其它相关文章!
微信app下载
微信是一款手机通信软件,支持通过手机网络发送语音短信、视频、图片和文字。微信可以单聊及群聊,还能根据地理位置找到附近的人,带给大家全新的移动沟通体验,有需要的小伙伴快来保存下载体验吧!