diff --git a/app/(tabs)/index.tsx b/app/(tabs)/index.tsx index e8893b7..322dc9d 100644 --- a/app/(tabs)/index.tsx +++ b/app/(tabs)/index.tsx @@ -32,6 +32,7 @@ export default function HomeScreen() { const [matches, setMatches] = useState([]); const [loading, setLoading] = useState(true); const [loadingLeagues, setLoadingLeagues] = useState(false); + const [now, setNow] = useState(() => new Date()); // Selection States // 默认足球 @@ -51,6 +52,12 @@ export default function HomeScreen() { loadLeagues(); }, []); + // 当前时间:每秒刷新(用于展示“现在时间/时区”) + useEffect(() => { + const id = setInterval(() => setNow(new Date()), 1000); + return () => clearInterval(id); + }, []); + // Load Matches when sport or date changes useEffect(() => { if (selectedSportId !== null) { @@ -58,6 +65,23 @@ export default function HomeScreen() { } }, [selectedSportId, selectedDate]); + const timezoneLabel = useMemo(() => { + // 仅展示 UTC 偏移(不展示时区名) + const offsetMin = -now.getTimezoneOffset(); + const sign = offsetMin >= 0 ? "+" : "-"; + const abs = Math.abs(offsetMin); + const hh = String(Math.floor(abs / 60)).padStart(2, "0"); + const mm = String(abs % 60).padStart(2, "0"); + return `UTC${sign}${hh}`; + }, [now]); + + const nowTimeText = useMemo(() => { + const hh = String(now.getHours()).padStart(2, "0"); + const mm = String(now.getMinutes()).padStart(2, "0"); + const ss = String(now.getSeconds()).padStart(2, "0"); + return `${hh}:${mm}`; + }, [now]); + // Load Leagues when sport changes useEffect(() => { if (selectedSportId !== null) { @@ -232,8 +256,7 @@ export default function HomeScreen() { {selectedDate.getDate()} - {selectedDate.getHours()}: - {selectedDate.getMinutes().toString().padStart(2, "0")} + {timezoneLabel} {nowTimeText} ) : ( @@ -364,10 +387,12 @@ const styles = StyleSheet.create({ }, dateDayText: { fontSize: 16, + lineHeight: 16, fontWeight: "bold", }, dateMonthText: { - fontSize: 10, + fontSize: 12, + lineHeight: 12, opacity: 0.6, }, listContent: {