美国时间显示

This commit is contained in:
Phoenix 2025-05-26 15:13:40 +08:00
parent f72dd8ad9d
commit c4a8271816
3 changed files with 43 additions and 35 deletions

View File

@ -18,6 +18,7 @@
"axios": "^1.7.3", "axios": "^1.7.3",
"cnjm-postcss-px-to-viewport": "^1.0.1", "cnjm-postcss-px-to-viewport": "^1.0.1",
"countup.js": "^2.8.2", "countup.js": "^2.8.2",
"dayjs": "^1.11.13",
"echarts": "^5.6.0", "echarts": "^5.6.0",
"gsap": "^3.12.5", "gsap": "^3.12.5",
"jsdom": "^24.0.0", "jsdom": "^24.0.0",

View File

@ -29,6 +29,9 @@ importers:
countup.js: countup.js:
specifier: ^2.8.2 specifier: ^2.8.2
version: 2.8.2 version: 2.8.2
dayjs:
specifier: ^1.11.13
version: 1.11.13
echarts: echarts:
specifier: ^5.6.0 specifier: ^5.6.0
version: 5.6.0 version: 5.6.0
@ -2068,6 +2071,9 @@ packages:
date-fns@3.6.0: date-fns@3.6.0:
resolution: {integrity: sha512-fRHTG8g/Gif+kSh50gaGEdToemgfj74aRX3swtiouboip5JDLAyDE9F11nHMIcvOaXeOC6D7SpNhi7uFyB7Uww==} resolution: {integrity: sha512-fRHTG8g/Gif+kSh50gaGEdToemgfj74aRX3swtiouboip5JDLAyDE9F11nHMIcvOaXeOC6D7SpNhi7uFyB7Uww==}
dayjs@1.11.13:
resolution: {integrity: sha512-oaMBel6gjolK862uaPQOVTA7q3TZhuSvuMQAAglQDOWYO9A91IrAOUJEyKVlqJlHE0vq5p5UXxzdPfMH/x6xNg==}
debug@4.3.6: debug@4.3.6:
resolution: {integrity: sha512-O/09Bd4Z1fBrU4VzkhFqVgpPzaGbw6Sm9FEkBT1A/YBXQFGuuSxa1dN2nxgxS34JmKXqYx8CZAwEVoJFImUXIg==} resolution: {integrity: sha512-O/09Bd4Z1fBrU4VzkhFqVgpPzaGbw6Sm9FEkBT1A/YBXQFGuuSxa1dN2nxgxS34JmKXqYx8CZAwEVoJFImUXIg==}
engines: {node: '>=6.0'} engines: {node: '>=6.0'}
@ -6478,6 +6484,8 @@ snapshots:
date-fns@3.6.0: {} date-fns@3.6.0: {}
dayjs@1.11.13: {}
debug@4.3.6: debug@4.3.6:
dependencies: dependencies:
ms: 2.1.2 ms: 2.1.2

View File

@ -1,6 +1,9 @@
import { ref } from 'vue' import { ref } from 'vue'
import { createGlobalState, useLocalStorage } from '@vueuse/core' import { createGlobalState, useLocalStorage } from '@vueuse/core'
import axios from 'axios' import axios from 'axios'
import dayjs from 'dayjs'
import utc from 'dayjs/plugin/utc'
import timezone from 'dayjs/plugin/timezone'
export const useStockQuote = createGlobalState(() => { export const useStockQuote = createGlobalState(() => {
const stockQuote = useLocalStorage('stockQuote', { const stockQuote = useLocalStorage('stockQuote', {
@ -14,47 +17,43 @@ export const useStockQuote = createGlobalState(() => {
"" ""
] ]
}) })
const date = new Date();
const options = {
year: 'numeric',
month: 'short',
day: 'numeric',
hour: 'numeric',
minute: '2-digit',
hour12: true,
timeZone: 'America/New_York',
timeZoneName: 'short'
};
// 计算美东时间的当前时间 dayjs.extend(utc)
function getTargetFridayTime() { dayjs.extend(timezone)
// 当前美东时间
const now = new Date(new Date().toLocaleString('en-US', { timeZone: 'America/New_York' }))
// 获取今天是周几0=周日, 1=周一, ..., 5=周五, 6=周六)
const day = now.getDay()
// 计算本周五的日期
const diffToFriday = 5 - day
const thisFriday = new Date(now)
thisFriday.setDate(now.getDate() + diffToFriday)
thisFriday.setHours(16, 0, 0, 0) // 设置为16:00:00
if (now >= thisFriday) { const getFormattedFriday = () => {
// 当前时间在本周五16:00及以后显示本周五16:00 const now = dayjs().tz('America/New_York')
return thisFriday // 本周五16:00
} else { const thisFriday = now.day() >= 5
// 当前时间早于本周五16:00显示上周五16:00 ? now.day(5).hour(16).minute(0).second(0).millisecond(0)
const lastFriday = new Date(thisFriday) : now.day(5 - 7).hour(16).minute(0).second(0).millisecond(0)
lastFriday.setDate(thisFriday.getDate() - 7) // 判断当前是否已到本周五16:00
return lastFriday let showFriday
} if (now.isAfter(thisFriday)) {
showFriday = thisFriday
} else {
// 上周五16:00
showFriday = thisFriday.subtract(7, 'day')
} }
return showFriday.format('MMM D, YYYY, h:mm A [EDT]')
}
const options = { const formatted = ref(getFormattedFriday())
year: 'numeric', const getStockQuate= async()=>{
month: 'short',
day: 'numeric',
hour: 'numeric',
minute: '2-digit',
hour12: true,
timeZone: 'America/New_York',
timeZoneName: 'short'
};
const formatted = ref(getTargetFridayTime().toLocaleString('en-US', options))
const getStockQuate= async()=>{
const res = await axios.get('https://saas-test.szjixun.cn/api/chart/forward/test') const res = await axios.get('https://saas-test.szjixun.cn/api/chart/forward/test')
stockQuote.value=res.data stockQuote.value=res.data
} }
return { return {
formatted, formatted,
getStockQuate, getStockQuate,