refactor: 使用 Intl.DateTimeFormat 生成时间戳
This commit is contained in:
@@ -217,16 +217,15 @@ class VersionInjectPlugin {
|
|||||||
console.log(`[H5Zip] 输出目录名正确: ${outputDirName}`);
|
console.log(`[H5Zip] 输出目录名正确: ${outputDirName}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 上海时区时间戳格式: 20260511_1058
|
// 标准时区时间戳格式: 20260511_1058
|
||||||
const now = new Date();
|
const fmt = new Intl.DateTimeFormat('en-CA', {
|
||||||
const shanghaiOffset = 8 * 60;
|
timeZone: 'Asia/Shanghai',
|
||||||
const shanghaiTime = new Date(now.getTime() + shanghaiOffset * 60 * 1000);
|
year: 'numeric', month: '2-digit', day: '2-digit',
|
||||||
const y = shanghaiTime.getFullYear();
|
hour: '2-digit', minute: '2-digit', hour12: false
|
||||||
const M = String(shanghaiTime.getMonth() + 1).padStart(2, '0');
|
});
|
||||||
const d = String(shanghaiTime.getDate()).padStart(2, '0');
|
const parts = fmt.formatToParts(new Date());
|
||||||
const h = String(shanghaiTime.getHours()).padStart(2, '0');
|
const get = (t) => parts.find(p => p.type === t).value;
|
||||||
const m = String(shanghaiTime.getMinutes()).padStart(2, '0');
|
const ts = `${get('year')}${get('month')}${get('day')}_${get('hour')}${get('minute')}`;
|
||||||
const ts = `${y}${M}${d}_${h}${m}`;
|
|
||||||
|
|
||||||
const zipFileName = `${outputDirName}-${this._cachedCommitId}-${ts}.zip`;
|
const zipFileName = `${outputDirName}-${this._cachedCommitId}-${ts}.zip`;
|
||||||
const zipFilePath = path.join(h5Dir, zipFileName);
|
const zipFilePath = path.join(h5Dir, zipFileName);
|
||||||
|
|||||||
Reference in New Issue
Block a user