如何更改日期本地化并显示新的本地化日期?
const Locale = () => {
return (
<div>
<button onClick={() => moment.locale("en")}>English</button>
<button onClick={() => moment.locale("de")}>German</button>
<p>{moment().format("LLLL")}</p>
</div>
);
};
codesandbox示例https://codesandbox.io/s/vigorous-violet-v0hvf
const deMoment = moment().locale("de").format("LLLL");
const enMoment = moment().locale("en").format("LLLL");
const Locale = () => {
const [momentDate, setMomentDate] = useState(deMoment);
useEffect(() => {}, [momentDate]);
return (
<div>
<button onClick={() => setMomentDate(enMoment)}>English</button>
<button onClick={() => setMomentDate(deMoment)}>German</button>
<p>{momentDate}</p>
</div>
);
};