mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-03-29 06:09:45 +08:00
🚨 fix command warn
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @file utils/toolFunc.ts
|
||||
* @description 一些工具函数
|
||||
* @since Beta v0.6.8
|
||||
* @since Beta v0.7.2
|
||||
*/
|
||||
|
||||
import { path } from "@tauri-apps/api";
|
||||
@@ -45,6 +45,34 @@ export function timestampToDate(timestamp: number): string {
|
||||
return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取相近时间
|
||||
* @description 如果是今天,只显示 hh:mm
|
||||
* @description 如果是今年,显示 MM-dd
|
||||
* @description 否则显示 yyyy-MM-dd
|
||||
* @since Beta v0.7.2
|
||||
* @param {number} timestamp - 时间戳(秒)
|
||||
* @returns {string} 相近时间
|
||||
*/
|
||||
export function getNearTime(timestamp: number): string {
|
||||
const date = new Date(timestamp * 1000);
|
||||
const now = new Date();
|
||||
const year = date.getFullYear();
|
||||
const month = String(date.getMonth() + 1).padStart(2, "0");
|
||||
const day = String(date.getDate()).padStart(2, "0");
|
||||
const hour = String(date.getHours()).padStart(2, "0");
|
||||
const minute = String(date.getMinutes()).padStart(2, "0");
|
||||
if (
|
||||
now.getFullYear() === year &&
|
||||
now.getMonth() === date.getMonth() &&
|
||||
now.getDate() === date.getDate()
|
||||
) {
|
||||
return `${hour}:${minute}`;
|
||||
}
|
||||
if (now.getFullYear() === year) return `${month}-${day}`;
|
||||
return `${year}-${month}-${day}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取设备信息(初始化时)
|
||||
* @since Beta v0.4.1
|
||||
|
||||
Reference in New Issue
Block a user