1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- var formatNumber = function (n) {
- n = n.toString()
- return n[1] ? n : '0' + n
- }
- /**
- * 将时间戳(1570550400)格式转为 yyyy-MM-dd格式
- */
- //时间戳转时间
- function formatDate(time, flag) {
- if (!time) {
- return
- }
- var time = time * 1
- var t = getDate(time);
- var tf = function (i) {
- return (i < 10 ? '0' : '') + i
- };
- var year = t.getFullYear();
- var month = tf(t.getMonth() + 1);
- var day = tf(t.getDate());
- var hour = tf(t.getHours());
- var minute = tf(t.getMinutes());
- if (flag == 1) {
- return month + '月' + day + '日' + ' ' + hour + ':' + minute;
- } else if (flag == 2) {
- 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 gradeFilter(grade) {
- if (!grade) {
- return '暂无'
- }
- var gradeObj = {
- "PRIMARY_FIRST_GRADE": "一年级",
- "PRIMARY_SECOND_GRADE": "二年级",
- "PRIMARY_THREE_GRADE": "三年级",
- "PRIMARY_SENIOR_GRADE": "四年级",
- "PRESCHOOL": "学前班",
- }
- return gradeObj[grade]
- }
- // 数字满万补w
- function numFilter(num) {
- if (!num || num < 10000) {
- return num
- }
- return Math.floor(num / 100) / 100 + 'w'
- }
- module.exports = {
- formatDate: formatDate,
- gradeFilter: gradeFilter,
- numFilter: numFilter
- }
|