You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Global-sales/src/views/Conversations/Online/LocalTimeClock.jsx

45 lines
1.3 KiB
JavaScript

import { useEffect, useState } from 'react';
import { Typography } from 'antd';
// import { useConversationState } from '@/stores/ConversationContext';
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import timezone from 'dayjs/plugin/timezone';
dayjs.extend(utc);
dayjs.extend(timezone);
const LocalTimeClock = ((props) => {
// const { customerOrderProfile: orderInfo } = useConversationState();
const [customerDateTime, setCustomerDateTime] = useState();
// todo: 用dayjs 显示指定时区的时间
useEffect(() => {
const intervalId = setInterval(() => {
// if (customerProfile && customerProfile.timezone) {
const date = new Date();
const options = {
year: 'numeric',
month: 'long',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
hour12: true,
};
const formatter = new Intl.DateTimeFormat('cn-ZH', options); // todo:
setCustomerDateTime(formatter.format(date));
// }
}, 1000); // Update every second
// Cleanup function to clear the interval when the component is unmounted
return () => clearInterval(intervalId);
}, []);
return (
<>
<Typography.Text>{customerDateTime}</Typography.Text>
</>
);
});
export default LocalTimeClock;