diff --git a/agent/app/service/dashboard.go b/agent/app/service/dashboard.go index 2e28d00de8ed..312364fa5e18 100644 --- a/agent/app/service/dashboard.go +++ b/agent/app/service/dashboard.go @@ -180,7 +180,7 @@ func (u *DashboardService) LoadCurrentInfo(ioOption string, netOption string) *d var currentInfo dto.DashboardCurrent hostInfo, _ := psutil.HOST.GetHostInfo(false) currentInfo.Uptime = hostInfo.Uptime - currentInfo.TimeSinceUptime = time.Now().Add(-time.Duration(hostInfo.Uptime) * time.Second).Format(constant.DateTimeLayout) + currentInfo.TimeSinceUptime = time.Unix(int64(hostInfo.BootTime), 0).Format(constant.DateTimeLayout) currentInfo.Procs = hostInfo.Procs currentInfo.CPUTotal, _ = psutil.CPUInfo.GetLogicalCores(false) diff --git a/frontend/src/utils/util.ts b/frontend/src/utils/util.ts index 7e8c241385b5..aeef571a2ff2 100644 --- a/frontend/src/utils/util.ts +++ b/frontend/src/utils/util.ts @@ -56,14 +56,17 @@ export function getBrowserLang() { return defaultBrowserLang; } -export function loadUpTime(uptime: number) { +export function loadUpTime(timeSince: string) { + const targetTime = new Date(timeSince); + const currentTime = new Date(); + const uptime = (currentTime.getTime() - targetTime.getTime()) / 1000; if (uptime <= 0) { return '-'; } let days = Math.floor(uptime / 86400); let hours = Math.floor((uptime % 86400) / 3600); let minutes = Math.floor((uptime % 3600) / 60); - let seconds = uptime % 60; + let seconds = Math.floor(uptime % 60); if (days !== 0) { return ( days + diff --git a/frontend/src/views/home/index.vue b/frontend/src/views/home/index.vue index 23f9f0fc5c1d..0de05e61e2e8 100644 --- a/frontend/src/views/home/index.vue +++ b/frontend/src/views/home/index.vue @@ -261,7 +261,7 @@ - {{ loadUpTime(currentInfo.uptime) }} + {{ loadUpTime(currentInfo.timeSinceUptime) }} @@ -689,7 +689,7 @@ const handleCopy = () => { '\n' + i18n.global.t('home.runningTime') + ': ' + - loadUpTime(currentInfo.value.uptime) + + loadUpTime(currentInfo.value.timeSinceUptime) + '\n'; copyText(content); };