sort/components/Time.tsx
2024-10-16 10:37:18 +07:00

31 lines
964 B
TypeScript

import React, { useEffect } from "react";
import { View,Text } from "react-native"
const TimeLive = ({ styleTime }:any) => {
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>
<Text style={[{
fontSize: 12,
paddingVertical: 10,
fontWeight: 'bold',
}, styleTime]}>{formatDate(currentTime)}</Text>
</View>
</>
}
export default TimeLive;