Skip to main content

dayjs

安装

npm i dayjs

官方

https://day.js.org/

日期格式化

http://localhost:3000
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;

日期比较

http://localhost:3000
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;