123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- 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 lastHours = date => {
- let h = parseInt((date % (1000 * 60 * 60 * 72)) / (1000 * 60 * 60));
- let m = parseInt((date % (1000 * 60 * 60)) / (1000 * 60));
- return h + '小时' + m + '分'
- }
- const addThreeYears = date => {
- // const t = date + (31536000000 * 3)
- const t = date
- return formatDate(t, 4)
- }
- const lastHoursInGroup = date => {
- // const temp = [];
- let h = parseInt((date % (1000 * 60 * 60 * 72)) / (1000 * 60 * 60));
- let m = parseInt((date % (1000 * 60 * 60)) / (1000 * 60));
- return [h.toString(), m.toString()]
- }
- const formatNumber = n => {
- n = n.toString()
- return n[1] ? n : '0' + n
- }
- //时间戳转时间
- function formatDate(time, flag) {
- 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;
- } else if (flag == 4) {
- return year + '年' + month + '月' + day + '日';
- } else if (flag == 5) {
- return day.toString().substring(1, 2)
- } else if (flag == 6) {
- return month + '.' + day;
- }
- }
- function GetQueryString(str, name) {
- var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
- var r = str.match(reg);
- if (r != null) return unescape(r[2]);
- return null;
- }
- function gradeFilter(grade) {
- console.log(grade);
- let gradeObj = {
- "PRIMARY_FIRST_GRADE": "一年级",
- "PRIMARY_SECOND_GRADE": "二年级",
- "PRIMARY_THREE_GRADE": "三年级",
- "PRIMARY_SENIOR_GRADE": "四年级",
- "PRESCHOOL": "学前班",
- }
- return gradeObj[grade]
- }
- module.exports = {
- formatTime: formatTime,
- formatDate,
- GetQueryString,
- lastHours,
- lastHoursInGroup,
- addThreeYears,
- gradeFilter
- }
|