显示时区
This commit is contained in:
@@ -32,6 +32,7 @@ export default function HomeScreen() {
|
|||||||
const [matches, setMatches] = useState<Match[]>([]);
|
const [matches, setMatches] = useState<Match[]>([]);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [loadingLeagues, setLoadingLeagues] = useState(false);
|
const [loadingLeagues, setLoadingLeagues] = useState(false);
|
||||||
|
const [now, setNow] = useState(() => new Date());
|
||||||
|
|
||||||
// Selection States
|
// Selection States
|
||||||
// 默认足球
|
// 默认足球
|
||||||
@@ -51,6 +52,12 @@ export default function HomeScreen() {
|
|||||||
loadLeagues();
|
loadLeagues();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
// 当前时间:每秒刷新(用于展示“现在时间/时区”)
|
||||||
|
useEffect(() => {
|
||||||
|
const id = setInterval(() => setNow(new Date()), 1000);
|
||||||
|
return () => clearInterval(id);
|
||||||
|
}, []);
|
||||||
|
|
||||||
// Load Matches when sport or date changes
|
// Load Matches when sport or date changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (selectedSportId !== null) {
|
if (selectedSportId !== null) {
|
||||||
@@ -58,6 +65,23 @@ export default function HomeScreen() {
|
|||||||
}
|
}
|
||||||
}, [selectedSportId, selectedDate]);
|
}, [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
|
// Load Leagues when sport changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (selectedSportId !== null) {
|
if (selectedSportId !== null) {
|
||||||
@@ -232,8 +256,7 @@ export default function HomeScreen() {
|
|||||||
{selectedDate.getDate()}
|
{selectedDate.getDate()}
|
||||||
</ThemedText>
|
</ThemedText>
|
||||||
<ThemedText style={styles.dateMonthText}>
|
<ThemedText style={styles.dateMonthText}>
|
||||||
{selectedDate.getHours()}:
|
{timezoneLabel} {nowTimeText}
|
||||||
{selectedDate.getMinutes().toString().padStart(2, "0")}
|
|
||||||
</ThemedText>
|
</ThemedText>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
) : (
|
) : (
|
||||||
@@ -364,10 +387,12 @@ const styles = StyleSheet.create({
|
|||||||
},
|
},
|
||||||
dateDayText: {
|
dateDayText: {
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
|
lineHeight: 16,
|
||||||
fontWeight: "bold",
|
fontWeight: "bold",
|
||||||
},
|
},
|
||||||
dateMonthText: {
|
dateMonthText: {
|
||||||
fontSize: 10,
|
fontSize: 12,
|
||||||
|
lineHeight: 12,
|
||||||
opacity: 0.6,
|
opacity: 0.6,
|
||||||
},
|
},
|
||||||
listContent: {
|
listContent: {
|
||||||
|
|||||||
Reference in New Issue
Block a user