```js
export function dateFormat(date) {
let format = 'yyyy-MM-dd hh:mm:ss';
if (date != 'Invalid Date') {
var o = {
"M+": date.getMonth() + 1, //month
"d+": date.getDate(), //day
"h+": date.getHours(), //hour
"m+": date.getMinutes(), //minute
"s+": date.getSeconds(), //second
"q+": Math.floor((date.getMonth() + 3) / 3), //quarter
"S": date.getMilliseconds() //millisecond
}
if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
(date.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(format))
format = format.replace(RegExp.$1,
RegExp.$1.length == 1 ? o[k] :
("00" + o[k]).substr(("" + o[k]).length));
return format;
}
return '';
}
```
### 格式话
```js
export default function (date, fmt = 'YYYY-MM-DD HH:mm:ss') {
var o = {
'M+': date.getMonth() + 1,
'D+': date.getDate(),
'h+': date.getHours() % 12 === 0 ? 12 : date.getHours() % 12,
'H+': date.getHours(),
'm+': date.getMinutes(),
's+': date.getSeconds(),
'q+': Math.floor((date.getMonth() + 3) / 3),
'S': date.getMilliseconds()
}
var week = {
'0': '\u65e5',
'1': '\u4e00',
'2': '\u4e8c',
'3': '\u4e09',
'4': '\u56db',
'5': '\u4e94',
'6': '\u516d'
}
if (/(Y+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
}
if (/(E+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? '\u661f\u671f' : '\u5468') : '') + week[date.getDay() + ''])
}
for (var k in o) {
if (new RegExp('(' + k + ')').test(fmt)) {
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)))
}
}
return fmt
}
```
### 格式化
```
Date.prototype.format = function (pattern) {
let pad = function (source, length) {
let pre = "",
negative = (source < 0),
string = String(Math.abs(source));
if (string.length < length) {
pre = (new Array(length - string.length + 1)).join('0');
}
return (negative ? "-" : "") + pre + string;
};
if (typeof pattern !== 'string') {
return this.toString();
}
let replacer = function (patternPart, result) {
pattern = pattern.replace(patternPart, result);
};
let year = this.getFullYear(),
month = this.getMonth() + 1,
date2 = this.getDate(),
hours = this.getHours(),
minutes = this.getMinutes(),
seconds = this.getSeconds(),
milliSec = this.getMilliseconds();
replacer(/yyyy/g, pad(year, 4));
replacer(/yy/g, pad(parseInt(year.toString().slice(2), 10), 2));
replacer(/MM/g, pad(month, 2));
replacer(/M/g, month);
replacer(/dd/g, pad(date2, 2));
replacer(/d/g, date2);
replacer(/HH/g, pad(hours, 2));
replacer(/H/g, hours);
replacer(/hh/g, pad(hours % 12, 2));
replacer(/h/g, hours % 12);
replacer(/mm/g, pad(minutes, 2));
replacer(/m/g, minutes);
replacer(/ss/g, pad(seconds, 2));
replacer(/s/g, seconds);
replacer(/SSS/g, pad(milliSec, 3));
replacer(/S/g, milliSec);
return pattern;
};
```
- LOLKU
- 工具类
- form/formData
- form
- formData
- iframe
- 渲染数据,防止内存泄漏
- 获取url(路由)参数
- 常用方法
- 失去焦点软键盘页面乱
- 判断数据类型
- 浏览器全屏
- 动态插入css
- 随机生成自定义长度位数数字
- 验证判断
- localStorage 封装存储
- 格式化日期
- 计算两个时间差
- 去除空格
- 将驼峰命名转换为连字符
- 获取dom属性
- 深拷贝
- class操作
- 判断是否打开浏览器控制台
- 全国城市地区代码表
- canvas合成工具
- 去除emoji表情符号
- 比较两个对象属性和内容(值)一致
- 微信结束页面事件
- 正则匹配url替换域名
- 字符串拼接(渲染dom后传值)
- 判断是否是正则
- 日历算法
- json 工具
- 是否支持webp格式
- h5底部输入框被键盘遮挡问题
- php
- php 二级域名管理
- 单个或者多个域名跨域
- file_get_contents 正确使用
- fromData请求无法携带cookie
- 简单的加密文件传输
- css
- 1px
- 滚动
- ios点击有颜色
- 文本溢出省略号
- css动画抖动
- 文本换行与不换行
- 阻止旋转屏幕时自动调整字体大小
- vue
- vscode 调试
- 新技术
- vue-router 4.0
- vue3
- 基础
- 试验
- javascript
- 上传问题
- 文件选中过,第二次再次选中不触发change事件
- 上传oss
- 后台
- linux搭建服务
- 需安装
- nginx
- 安装
- nginx http 配置二级域名
- nginx https 配置二级域名
- 防止暴力破解
- 阿里申请免费https
- git
- 快速安装
- 配置项
- node
- 安装
- pm2
- mysql
- 安装
- 创建、切换、查询数据库
- 常用命令
- cmake 编译器
- redis
- 软件下载
- git
- 百度git 记住密码
- 经验
- 上传
- 软件
- vscode
- 推荐插件
- 应用开发
- nwjs
- 入门
- package.json
- vue、react、angular 跑nwjs
- 打包
- 监听屏幕
- 运行另一个.exe文件
- node应用
- electron
- 资料
- 安装
- 实战
- 崩溃日志报告
- electron-forge
- 托盘闪烁
- 开机自动启动
- 消息通知
- 禁止默认事件
- 保证只有一个实例
- 打包且美化安装界面
- 创建cli
- 添加Github徽章
- 自动更新
- docsify
- Lowdb存储数据
- 备份、恢复、导入、导出
- 深度链接(协议)唤起Electron应用
- 说明
- 加载扩展插件
- 证书
- Sketch 插件
- 工作
- 宣传文章地址
- api
- tinypng
- npm 插件
- fs封装:fs-jetpack
- 判断是否npm或yarn运行
- 字符串或缓冲区的gzip压缩大小
- 克隆并修改RegExp实例
- 反转对象的键/值
- http路由find-my-way
- dragula 拖拽(拖放)
- svga
- npm 脚手架搭建
- 项目
- 小工具
- svg转图片
- 日历