123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- const formatTime = date => {
- console.log(date);
- const day = parseInt(date / 1000 / 60 / 60 / 24);
- const hour = parseInt(date / 1000 / 60 / 60 % 24);
- const minute = parseInt(date / 1000 / 60 % 60);
- const arr = [hour, minute].map(formatNumber);
- arr.unshift(day);
- return arr
- }
- const formatNumber = n => {
- n = n.toString()
- return n[1] ? n : '0' + n
- }
- //时间戳转时间
- function formatDate(time, flag) {
- console.log(time)
- const t = new Date(time);
- const tf = function(i){return (i < 10 ? '0' : '') + i};
- const year = t.getFullYear();
- const month = tf(t.getMonth() + 1);
- const day = tf(t.getDate());
- const hour = tf(t.getHours());
- const minute = tf(t.getMinutes());
- //console.log( month + '月' + day + '日' + hour + ':' + minute);
- if(flag == 1) {
- return month + '月' + day + '日' + ' ' + hour + ':' + minute;
- }else if(flag == 2) {
- console.log(year,month,day)
- return year + '-' + month + '-' + day
- }else if(flag == 3){
- return month + '-' + day + ' ' + hour + ':' + minute;
- }
- }
- function GetQueryString(str,name){
- var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
- var r = str.match(reg);
- if(r!=null) return unescape(r[2]);
- return null;
- }
- module.exports = {
- formatTime: formatTime,
- formatDate,
- GetQueryString
- }
|