dayjs
安装
npm i dayjs
官方
日期格式化
http://localhost:3000
- tsx
- output
import dayjs from 'dayjs';
import { FC } from 'react';
const DayjsFormat: FC = () => {
return <div>{dayjs().format('YYYY-MM-DD HH:mm:ss')}</div>;
};
export default DayjsFormat;
2025-09-17 05:51:30
日期比较
http://localhost:3000
- tsx
- output
import dayjs from 'dayjs';
import { FC } from 'react';
const now = dayjs();
const DayjsCompare: FC = () => {
return (
<div>
<div>
now isAfter than 2022-01-01?{' '}
{now.isAfter(dayjs('2022-01-01')) ? 'true' : 'false'}
</div>
<div>
now isBefore than 2022-01-01?{' '}
{now.isBefore(dayjs('2022-01-01')) ? 'true' : 'false'}
</div>
</div>
);
};
export default DayjsCompare;
now isAfter than 2022-01-01? true
now isBefore than 2022-01-01? false