export async function getTimeInfo(format: string = "iso") {
const now = new Date();
const timeInfo = {
timestamp: now.getTime(),
iso: now.toISOString(),
locale: now.toLocaleString(),
utc: now.toUTCString(),
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
timezoneOffset: now.getTimezoneOffset(),
year: now.getFullYear(),
month: now.getMonth() + 1,
day: now.getDate(),
hour: now.getHours(),
minute: now.getMinutes(),
second: now.getSeconds(),
dayOfWeek: now.toLocaleDateString('zh-CN', { weekday: 'long' }),
};
// 根据格式返回不同的结果
if (format === "unix") {
return {
timestamp: timeInfo.timestamp,
timezone: timeInfo.timezone,
};
} else if (format === "locale") {
return {
locale: timeInfo.locale,
timezone: timeInfo.timezone,
dayOfWeek: timeInfo.dayOfWeek,
};
}
return timeInfo;
}