```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轉圖片
- 日歷