我在项目中使用Ant Design 日历组件,并按照以下方式设置:
当前星期几的格式为
是否可以通过props更改格式为
dd
。例如: Su
, Mo
, Tu
等。是否可以通过props更改格式为
ddd
。例如:Sun
, Mon
, Tue
等?不能直接在 Ant Design 组件上更改此设置,但 Ant Design 在幕后使用 moment
,moment
使用 locale.weekdaysMin
,所以您可以导入 moment
并更改它们:
import moment from 'moment'
moment.updateLocale('en', {
weekdaysMin : ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
});
import React from "react";
import { Calendar } from "antd";
export const App = () => <Calendar className="my-calendar" />;
/* adds 'n' after "Su"*/
.my-calendar table thead tr > th:nth-child(1)::after {
content: "n";
}
/* adds 'n' after "Mo"*/
.my-calendar table thead tr > th:nth-child(2)::after {
content: "n";
}
/* ... etc., etc., ....*/
.my-calendar table thead tr > th:nth-child(3)::after {
content: "e";
}
.my-calendar table thead tr > th:nth-child(4)::after {
content: "d";
}
.my-calendar table thead tr > th:nth-child(5)::after {
content: "u";
}
.my-calendar table thead tr > th:nth-child(6)::after {
content: "i";
}
.my-calendar table thead tr > th:nth-child(7)::after {
content: "t";
}
你必须先使用变量设置格式:
const dateFormat = 'DDD/MM/YYYY';
然后在DatePicker中,您指出要使用自定义格式:
<DatePicker format = {dateFormat} />
<DatePicker
format = {dateFormat}
dateRender = {(current) => {
const num = (current.toString().length < 2) ? "0" + current : current)
return (
{num}
)
}}
/>