```
Date.prototype.format = function(formatStr) {
var str = formatStr;
var Week = ["日", "一", "二", "三", "四", "五", "六"];
str = str.replace(/yyyy|YYYY/, this.getFullYear());
str = str.replace(
/yy|YY/,
this.getYear() % 100 > 9
? (this.getYear() % 100).toString()
: "0" + (this.getYear() % 100)
);
str = str.replace(
/MM/,
this.getMonth() + 1 > 9
? (this.getMonth() + 1).toString()
: "0" + (this.getMonth() + 1)
);
str = str.replace(/M/g, this.getMonth() + 1);
str = str.replace(/w|W/g, Week[this.getDay()]);
str = str.replace(
/dd|DD/,
this.getDate() > 9 ? this.getDate().toString() : "0" + this.getDate()
);
str = str.replace(/d|D/g, this.getDate());
str = str.replace(
/hh|HH/,
this.getHours() > 9 ? this.getHours().toString() : "0" + this.getHours()
);
str = str.replace(/h|H/g, this.getHours());
str = str.replace(
/mm/,
this.getMinutes() > 9
? this.getMinutes().toString()
: "0" + this.getMinutes()
);
str = str.replace(/m/g, this.getMinutes());
str = str.replace(
/ss|SS/,
this.getSeconds() > 9
? this.getSeconds().toString()
: "0" + this.getSeconds()
);
str = str.replace(/s|S/g, this.getSeconds());
return str;
};
// 或
Date.prototype.format = function(format) {
var o = {
"M+": this.getMonth() + 1, //month
"d+": this.getDate(), //day
"h+": this.getHours(), //hour
"m+": this.getMinutes(), //minute
"s+": this.getSeconds(), //second
"q+": Math.floor((this.getMonth() + 3) / 3), //quarter
S: this.getMilliseconds() //millisecond
};
if (/(y+)/.test(format))
format = format.replace(
RegExp.$1,
(this.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;
};
alert(new Date().format("yyyy-MM-dd hh:mm:ss"));
```
- 學習網站
- iframe
- 跨域
- 渲染數據,防止內存泄漏
- 工具類
- 一般使用方法
- 獲取url(路由)參數
- HTML標簽轉義
- 轉義html標簽
- 加入收藏夾
- 提取頁面代碼中所有網址
- 動態加載腳本文件
- 返回頂部的通用方法
- 實現base64解碼
- 確認是否是鍵盤有效輸入值
- 全角半角轉換
- 版本對比
- 壓縮CSS樣式代碼
- 字符串長度截取
- 時間日期格式轉換
- 返回腳本內容
- 格式化CSS樣式代碼
- 獲取cookie值
- 獲得URL中GET參數值
- 獲取移動設備初始化大小
- 獲取頁面高度
- 獲取頁面scrollLeft
- 獲取頁面scrollTop
- 獲取頁面可視高度
- 獲取頁面可視寬度
- 獲取頁面寬度
- 獲取移動設備屏幕寬度
- 判斷是否移動設備
- 判斷是否是移動設備訪問
- 加載樣式文件
- 清除腳本內容
- 時間個性化輸出功能
- 金額大寫轉換函數
- 清除空格
- 隨機數時間戳
- 實現utf8解碼
- 返回字符串構成種類(字母,數字,標點符號)的數量
- 清除所有中文字符(包括中文標點符號)
- 清除所有中文字符及空格
- 校驗是否包含空格
- 校驗是否包含中文字符(包括中文標點符號)
- 校驗是否為網址
- 接成URL帶參數
- 獲取瀏覽器名稱
- 郵箱
- 手機號碼
- 根據url地址下載
- el是否包含某個class
- el添加某個class
- el去除某個class
- 獲取滾動的坐標
- 滾動到頂部
- el是否在視口范圍內
- 洗牌算法隨機
- 劫持粘貼板
- 嚴格的身份證校驗
- 隨機數范圍
- 將阿拉伯數字翻譯成中文的大寫數字
- 將數字轉換為大寫金額
- 檢測密碼強度
- 字符轉換首字大小寫
- 去除空格
- 最大值與最小值和平均值
- 函數節流器
- 16進制顏色轉RGBRGBA字符串
- 追加url參數
- base64文件轉文件和文件轉base64
- base64轉換為blob和blob轉換為file
- 生成 uid 或者 uuid 4種方法
- 正則
- 按復制快捷鍵或者右鍵復制
- 表情
- 獲取dom某個屬性上的值
- 獲取dom某個屬性的值
- 獲取系統
- 去除emoji表情符號
- 本地文件轉換 Bool url 訪問地址
- 禁止ios 擊穿后底部還能滑動
- 將數字負數轉換為字符串類型
- 將字符串類型數字判斷正負
- 判斷是否有小數點
- 判斷是否有科學技術法
- 去除0123字符串類型的數字
- 瀏覽器共享屏幕
- 兼容navigator.getUserMedia與AudioContext
- 音頻軌跡
- vue
- vue 技巧
- vue 2.xx 腳手架快速搭建環境
- vue 優化模塊
- css
- input或textarea_placeholder
- 布局巧
- form/formData
- form
- formData
- Visual-Studio-code
- VS Code
- vscode-fileheader 生成注釋
- View In Browser(右鍵瀏覽器預覽)
- Chinese (Simplified) Language(中文語音包)
- 北京地攤位置
- 輸入框使用第三方語音輸入文本問題
- adb 文檔
- serve后臺
- docker
- 介紹
- 安裝
- 常用命令
- mysql
- 安裝
- 破解Navicat Premium 無限試用
- 源碼技巧
- 實例化
- 判斷是否傳實例化對象
- 實例化構造函數
- ui 框架