123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- function formatTime(date) {
- var year = date.getFullYear()
- var month = date.getMonth() + 1
- var day = date.getDate()
- var hour = date.getHours()
- var minute = date.getMinutes()
- var second = date.getSeconds()
- return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
- }
- function Getdate(date) {
- var year = date.getFullYear()
- var month = date.getMonth() + 1
- var day = date.getDate()
- return [year, month, day].map(formatNumber).join('.')
- }
- function formatNumber(n) {
- n = n.toString()
- return n[1] ? n : '0' + n
- }
- module.exports = {
- Getdate:Getdate,
- formatTime: formatTime
- , showLoading: function (loading) {
- this.getCurrentPage().setData({
- show_loading: loading
- })
- }
- , showSuccess: function (title) {
- wx.showToast({
- title: title,
- icon: 'success',
- duration: 2000
- })
- }
- , showModal: function (title, content, cb) {
- wx.showModal({
- title: title,
- content: content == undefined ? '' : content,
- showCancel: false,
- success: function (res) {
- if (cb) {
- cb(res)
- }
- }
- })
- }
- // 获取当前页面
- ,getCurrentPage:function(){
- var arr = getCurrentPages();
- return arr[arr.length - 1]
- }
- /**获取今天零点的时间戳*/
- , getToday: function () {
- var today = new Date();
- today.setHours(0);
- today.setMinutes(0);
- today.setSeconds(0);
- today.setMilliseconds(0);
- return Math.floor(today.getTime() / 1000);
- },
- /**获取这个月的第一天时间戳*/
- getThisMonth: function () {
- var today = new Date();
- today.setDate(0);
- today.setHours(0);
- today.setMinutes(0);
- today.setSeconds(0);
- today.setMilliseconds(0);
- return Math.floor(today.getTime() / 1000);
- },
- /**获取实时时间戳*/
- getNowTimestamp: function () {
- return Math.floor(new Date().getTime() / 1000);
- },
- /**时间戳转日期格式*/
- timestamp2date: function format(timestamp) {
- function add0(m) { return m < 10 ? '0' + m : m }
- var time = new Date(timestamp);
- var y = time.getFullYear();
- var m = time.getMonth() + 1;
- var d = time.getDate();
- var h = time.getHours();
- var mm = time.getMinutes();
- var s = time.getSeconds();
- return y + '-' + add0(m) + '-' + add0(d) + ' ' + add0(h) + ':' + add0(mm) + ':' + add0(s);
- }
- //获取当前分钟数的时间戳
- , getNowMinute: function () {
- var today = new Date();
- today.setSeconds(0);
- today.setMilliseconds(0);
- return Math.floor(today.getTime() / 1000);
- }
- //获取当前小时数
- , getNowHour: function () {
- var today = new Date();
- today.setMilliseconds(0);
- today.setSeconds(0);
- today.setMinutes(0);
- return Math.floor(today.getTime() / 1000);
- }
- , getNowMinuteByTimestamp: function (timestamp) {
- var today = new Date(timestamp * 1000);
- today.setSeconds(0);
- today.setMilliseconds(0);
- return Math.floor(today.getTime() / 1000);
- }
- // 文件名
- , getFileName: function () {
- var timestamp = this.getNowTimestamp();
- function add0(m) { return m < 10 ? '0' + m : m }
- var time = new Date(timestamp * 1000);
- var y = time.getFullYear();
- var m = time.getMonth() + 1;
- var d = time.getDate();
- var h = time.getHours();
- var mm = time.getMinutes();
- var s = time.getSeconds();
- return y + '' + add0(m) + '' + add0(d) + '' + add0(h) + '' + add0(mm) + '' + add0(s);
- }
- , getNowTimeTag: function () {
- var timestamp = this.getNowTimestamp();
- function add0(m) { return m < 10 ? '0' + m : m }
- var time = new Date(timestamp * 1000);
- var y = time.getFullYear();
- var m = time.getMonth() + 1;
- var d = time.getDate();
- var h = time.getHours();
- var mm = time.getMinutes();
- var s = time.getSeconds();
- return y + '年' + add0(m) + '月' + add0(d) + '日';
- }
- //友好时间
- ,dateStr: function(date){
- //获取js 时间戳
- var time=new Date().getTime();
- //去掉 js 时间戳后三位,与php 时间戳保持一致
- time=parseInt((time-date*1000)/1000);
- //存储转换值
- var s;
- if(time<60*10){//十分钟内
- return '刚刚';
- }else if((time<60*60)&&(time>=60*10)){
- //超过十分钟少于1小时
- s = Math.floor(time/60);
- return s+"分钟前";
- }else if((time<60*60*24)&&(time>=60*60)){
- //超过1小时少于24小时
- s = Math.floor(time/60/60);
- return s+"小时前";
- }else if((time<60*60*24*3)&&(time>=60*60*24)){
- //超过1天少于3天内
- s = Math.floor(time/60/60/24);
- return s+"天前";
- }else{
- //超过3天
- var date= new Date(parseInt(date) * 1000);
- return date.getFullYear()+"/"+(date.getMonth()+1)+"/"+date.getDate();
- }
- }
-
- }
|