/**
* 获取当前日期:x年x月x日
*/
export const getNowDate = () => {
let time = new Date();
let year = time.getFullYear();
let month = time.getMonth() + 1 + "";
let data = time.getDate() + "";
if (month.length < 2) {
month = "0" + month;
}
if (data.length < 2) {
data = "0" + data;
}
let newtime = year + "年" + month + "月" + data + "日";
return newtime;
};
//时间戳转化为时间
timestampToTime:function(timestamp) {
var date = new Date(timestamp);//时间戳为10位需*1000,时间戳为13位的话不需乘1000
var Y = date.getFullYear() + '-';
var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
var D = (date.getDate()<10?'0'+date.getDate():date.getDate()) + ' ';
var h = (date.getHours()<10?'0'+date.getHours():date.getHours()) + ':';
var m = (date.getMinutes()<10?'0'+date.getMinutes():date.getMinutes()) + ':';
var s = (date.getSeconds()<10?'0'+date.getSeconds():date.getSeconds());
return Y+M+D+h+m+s;
},
/**
* 获取当前月份的第一天
*/
export const getDateFirstDay = (val) => {
var date = new Date(val);
date.setDate(1);
var month = parseInt(date.getMonth()+1);
var day = date.getDate();
var time = '00:00:00'
if (month < 10) {
month = '0' + month
}
if (day < 10) {
day = '0' + day
}
console.log(date.getFullYear() + '-' + month + '-' + day + ' ' + time);
return date.getFullYear() + '-' + month + '-' + day + ' ' + time
};
/**
* 获取当前月份的最后一天
*/
export const getDateLastDay = (val) => {
var date=new Date(val);
var currentMonth=date.getMonth();
var nextMonth=++currentMonth;
var nextMonthFirstDay=new Date(date.getFullYear(),nextMonth,1);
var oneDay=1000*60*60*24;
var lastTime = new Date(nextMonthFirstDay-oneDay);
var month = parseInt(lastTime.getMonth()+1);
var day = lastTime.getDate();
var time = '23:59:59'
if (month < 10) {
month = '0' + month
}
if (day < 10) {
day = '0' + day
}
console.log(typeof(date.getFullYear() + '-' + month + '-' + day + ' ' + time));
return date.getFullYear() + '-' + month + '-' + day + ' ' + time
};
/**
* 邮政编码校验
* 返回值: true/false
*/
export const postCodeCheck = value => {
let reg = /^[0-9]{6}$/;
let result = reg.test(value);
return result;
};
/**
* 手机号码校验
* 返回值: true/false
*/
export const mobileCheck = value => {
let reg = /^1[0-9][0-9]{9}$/;
let result = reg.test(value);
return result;
};
/**
* 电话号码校验
* 返回值: true/false
*/
export const telephoneCheck = value => {
let reg = /^0\d{2,3}-?\d{7,8}$/;
let result = reg.test(value);
return result;
};
/**
* 网址校验
* 返回值: true/false
*/
export const urlCheck = value => {
let str = `^((https|http|ftp|rtsp|mms)?://)`
+ `?(([0-9a-z_!~*'().&=+$%-]+:)?[0-9a-z_!~*'().&=+$%-]+@)?`// ftp的user@
+ `?(([0-9]{1,3}\.){3}[0-9]{1,3}`// IP形式的url
+ `|`// 允许IP和DOMAIN
+ `([0-9a-z_!~*'()-]+\.)*`// 域名-www
+ `([0-9a-z][0-9a-z]{0,61})?[0-9a-z]\.`// 二级域名
+ `[a-z]{2,6})`// first level domain-.com or .museum
+ `(:[0-9]{1,4})?`// 端口-:80
+ `((/?)|`// a slash isn't required if there is na file name
+ `(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$`;
let reg = new RegExp(str);
let result = reg.test(value);
return result;
};
/**
* 传真号码校验
* 返回值: true/false
*/
export const faxCheck = value => {
let reg = /^(\d{3,4})?[-]?\d{7,8}$/;
let result = reg.test(value);
return result;
};
/**
* 邮箱校验
* 返回值: true/false
*/
export const emailCheck = value => {
let reg = /^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/;
let result = reg.test(value);
return result;
};