@yoooloo42/bean 1.0.32 → 1.0.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +13 -7
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +13 -7
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -4183,6 +4183,12 @@ var GBT = {
|
|
|
4183
4183
|
* @returns {string} 格式化后的日期字符串
|
|
4184
4184
|
*/
|
|
4185
4185
|
function dateFormat(date, format) {
|
|
4186
|
+
let result = '';
|
|
4187
|
+
if(!date){
|
|
4188
|
+
return ''
|
|
4189
|
+
}
|
|
4190
|
+
const format0 = format || 'yyyy/MM/dd HH:mm:ss';
|
|
4191
|
+
|
|
4186
4192
|
// 有效的 Date 对象一致性
|
|
4187
4193
|
const Date0 = new Date(date);
|
|
4188
4194
|
|
|
@@ -4198,27 +4204,27 @@ function dateFormat(date, format) {
|
|
|
4198
4204
|
};
|
|
4199
4205
|
|
|
4200
4206
|
// 替换年份 'yyyy'
|
|
4201
|
-
if (/(y+)/.test(
|
|
4202
|
-
|
|
4207
|
+
if (/(y+)/.test(format0)) {
|
|
4208
|
+
result = format0.replace(RegExp.$1, (Date0.getFullYear() + "").substr(4 - RegExp.$1.length));
|
|
4203
4209
|
}
|
|
4204
4210
|
|
|
4205
4211
|
// 替换 'AM/PM'
|
|
4206
|
-
if (/(A|a)/.test(
|
|
4212
|
+
if (/(A|a)/.test(format0)) {
|
|
4207
4213
|
const ampm = Date0.getHours() < 12 ? 'AM' : 'PM';
|
|
4208
|
-
|
|
4214
|
+
result = format0.replace(RegExp.$1, RegExp.$1 === 'a' ? ampm.toLowerCase() : ampm);
|
|
4209
4215
|
}
|
|
4210
4216
|
|
|
4211
4217
|
// 替换其他时间单位 'MM', 'dd', 'HH' 等
|
|
4212
4218
|
for (let k in o) {
|
|
4213
|
-
if (new RegExp("(" + k + ")").test(
|
|
4219
|
+
if (new RegExp("(" + k + ")").test(format0)) {
|
|
4214
4220
|
const value = o[k];
|
|
4215
4221
|
// $1 匹配到的字符串,例如 'MM'
|
|
4216
4222
|
// 如果是毫秒 'S',则不补零
|
|
4217
|
-
|
|
4223
|
+
result = format0.replace(RegExp.$1, (RegExp.$1.length === 1) ? (value) : (("00" + value).substr(("" + value).length)));
|
|
4218
4224
|
}
|
|
4219
4225
|
}
|
|
4220
4226
|
|
|
4221
|
-
return
|
|
4227
|
+
return result;
|
|
4222
4228
|
}
|
|
4223
4229
|
|
|
4224
4230
|
/**
|