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