Forráskód Böngészése

[site]Modify vite build time

dufu1991 2 éve
szülő
commit
db47946982
3 módosított fájl, 25 hozzáadás és 3 törlés
  1. 1 0
      .gitignore
  2. 21 2
      site/scripts/env.js
  3. 3 1
      site/src/components/menu/Menu.svelte

+ 1 - 0
.gitignore

@@ -51,6 +51,7 @@ pnpm-lock.yaml
 /site/pnpm-lock.yaml
 /site/package-backup.json
 /site/public-backup
+/site/.env
 
 
 # 忽略 packages 中 stdf 本地构建的文件 ignore the files built by stdf in packages

+ 21 - 2
site/scripts/env.js

@@ -1,8 +1,27 @@
 import fs from 'node:fs';
 
+//得到标准时区的时间的函数
+const getLocalTime = i => {
+	//参数i为时区值数字,比如北京为东八区则输进8,纽约为西5区输入-5
+	if (typeof i !== 'number') return;
+	var d = new Date();
+	//得到1970年一月一日到现在的秒数
+	var len = d.getTime();
+	//本地时间与GMT时间的时间偏移差
+	var offset = d.getTimezoneOffset() * 60000;
+	//得到现在的格林尼治时间
+	var utcTime = len + offset;
+	return new Date(utcTime + 3600000 * i);
+};
+
 // 获取当前时间,返回中文和英文时间格式,24 小时制
-const now_en = new Date().toLocaleString('en-US', { hour12: false });
-const now_zh = new Date().toLocaleString('zh-CN', { hour12: false });
+let now_en = getLocalTime(-4).toLocaleString('en-US', { hour12: false });
+let now_zh = getLocalTime(+8).toLocaleString('zh-CN', { hour12: false });
+
+// 去掉秒,即去除最后的 ':xx'
+now_en = now_en.slice(0, -3) + '(UTC-04:00)';
+now_zh = now_zh.slice(0, -3) + '(UTC+08:00)';
+
 console.log('now_en', now_en);
 console.log('now_zh', now_zh);
 

+ 3 - 1
site/src/components/menu/Menu.svelte

@@ -15,7 +15,9 @@
 
 <div class="flex flex-col px-2 py-4">
 	<span class="text-gray-500 text-xs pb-3">
-		{isZh ? '最新:' + import.meta.env.VITE_BUILD_TIME_ZH : 'Latest: ' + import.meta.env.VITE_BUILD_TIME_EN}
+		{isZh ? '最近更新:' : 'Last update:'}
+		<br />
+		{isZh ? import.meta.env.VITE_BUILD_TIME_ZH : import.meta.env.VITE_BUILD_TIME_EN}
 	</span>
 	{#each menuList as menu}
 		<div class="text-xs">{isZh ? menu.class : menu.class_en}{showNum ? `(${menu.childs.length})` : ''}</div>