sort/components/Time.tsx

31 lines
964 B
TypeScript
Raw Permalink Normal View History

2024-09-07 01:22:11 +00:00
import React, { useEffect } from "react";
import { View,Text } from "react-native"
2024-10-16 03:37:18 +00:00
const TimeLive = ({ styleTime }:any) => {
2024-09-07 01:22:11 +00:00
const [currentTime, setCurrentTime] = React.useState(new Date());
useEffect(() => {
const timer = setInterval(() => {
setCurrentTime(new Date());
}, 1000);
return () => clearInterval(timer);
}, []);
const formatDate = (date: Date) => {
return `${String(date.getDate()).padStart(2, '0')}/${String(date.getMonth() + 1).padStart(2, '0')}/${date.getFullYear()} ${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}:${String(date.getSeconds()).padStart(2, '0')}`;
};
return <>
<View>
2024-10-16 03:37:18 +00:00
<Text style={[{
2024-09-07 01:22:11 +00:00
fontSize: 12,
paddingVertical: 10,
fontWeight: 'bold',
2024-10-16 03:37:18 +00:00
}, styleTime]}>{formatDate(currentTime)}</Text>
2024-09-07 01:22:11 +00:00
</View>
</>
}
export default TimeLive;