/** * 获取当前月天数 * @param {String} year 年份 * @param {String} month 月份 */export const getMonthNum = (year, month) => {var d = new Date(year, month, 0)return d.getDate()}复制代码
55.getYyMmDdHhMmSs获取当前时间 yyyy-mm-dd,hh:mm:ss
/** * 获取当前时间 yyyy-mm-dd,hh:mm:ss */export const getYyMmDdHhMmSs = () => {const date = new Date()const year = date.getFullYear()const month = date.getMonth() + 1const day = date.getDate()const hours = date.getHours()const minu = date.getMinutes()const second = date.getSeconds()const arr = [month, day, hours, minu, second]arr.forEach(item => {item < 10 ? '0' + item : item})return (year +'-' +arr[0] +'-' +arr[1] +' ' +arr[2] +':' +arr[3] +':' +arr[4])}复制代码
56.timesToYyMmDd时间戳转化为年月日
/** * 时间戳转化为年月日 * @param times 时间戳 * @param ymd 格式类型(yyyy-mm-dd,yyyy/mm/dd) * @param hms 可选,格式类型(hh,hh:mm,hh:mm:ss) * @returns {年月日} */export const timesToYyMmDd = (times, ymd,hms) => {const oDate = new Date(times)const oYear = oDate.getFullYear()const oMonth = oDate.getMonth() + 1const oDay = oDate.getDate()const oHour = oDate.getHours()const oMin = oDate.getMinutes()const oSec = oDate.getSeconds()let oTime // 最后拼接时间// 年月日格式switch (ymd) {case 'yyyy-mm-dd':oTime = oYear + '-' + getzf(oMonth) + '-' + getzf(oDay)breakcase 'yyyy/mm/dd':oTime = oYear + '/' + getzf(oMonth) + '/' + getzf(oDay)break}// 时分秒格式switch (hms) {case 'hh':oTime = ' '+oTime + getzf(oHour)breakcase 'hh:mm':oTime = oTime + getzf(oHour) + ':' + getzf(oMin)breakcase 'hh:mm:ss':oTime = oTime + getzf(oHour) + ':' + getzf(oMin) + ':' + getzf(oSec)break}return oTime}复制代码
57.YyMmDdToTimes将年月日转化成时间戳
/** * 将年月日转化成时间戳 * @param {String} time yyyy/mm/dd 或yyyy-mm-dd 或yyyy-mm-dd hh:mm 或yyyy-mm-dd hh:mm:ss */export const YyMmDdToTimes = (time) => {return new Date(time.replace(/-/g, '/')).getTime()}复制代码
58.compareTimeOneLessTwo/** *比较时间 1 小于时间 2 * @param {String} timeOne时间 1 * @param {String} timeTwo时间 2 */export const compareTimeOneLessTwo = (timeOne, timeTwo) => {// 判断 timeOne 和 timeTwo 是否return new Date(timeOne.replace(/-/g, '/')).getTime()<new Date(timeTwo.replace(/-/g, '/')).getTime()}复制代码
url59.getQueryString获取 url 后面通过?传参的参数~~~~
/** *获取 url 后面通过?传参的参数 * @param {String} name */export function getQueryString(name) {const reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i')const url = window.location.hrefconst search = url.substring(url.lastIndexOf('?') + 1)const r = search.match(reg)if (r != null) return unescape(r[2])return null}复制代码
总结码字不易,持续更新中,欢迎 start!
github地址:https://github.com/lanzhsh/react-vue-koa/tree/master/utils-lan
原链接:https://juejin.im/post/5de5be53f265da05c33fcbb4
推荐阅读
- 邻居家老蹭网,教你一招摆脱蹭网
- 中老年人怎样瘦肚子和腰?教你4个方法,消除腹部脂肪拥有好身材
- 教你如何识别我军3等10级的军官军衔,记住这3个要素就行了
- 花草茶常用有哪些,常用的花草茶有哪些
- 苦荞茶和黑苦荞哪个好,四大步骤教你如何简易而快速的冲泡百合花茶
- 膝盖疼就是关节炎吗?积水潭医生教你分辨
- 领导出现这几种行为,是逼员工主动离职,教你高情商反击
- 坚持长期喝茶有什么好处,教你九个喝茶的技巧
- 招聘|实用干货!20条HR常用的招聘问题!
- 怎样练习太极拳转腰跨 教你练习的小技巧