【问题标题】:Need to edit Moment in Antd Datepicker to display full name of month需要在 Antd Datepicker 中编辑 Moment 以显示月份的全名
【发布时间】:2019-07-09 17:48:52
【问题描述】:

我正在使用 Antd 的 DatePicker 组件,我正在尝试编辑负责处理月份名称的 Moment 函数。

到目前为止,我的组件显示缩短的名称,但我正在尝试将其更改为 MMMM 格式,以便显示月份的全名。

有谁知道如何做到这一点以及在组件级别是否可行?

My Component

import React from "react";
import ReactDOM from "react-dom";
import "antd/dist/antd.css";
import "./index.css";
import { DatePicker, Row, Col } from "antd";

function onChange(value, dateString) {
  console.log("Selected Time: ", value);
  console.log("Formatted Selected Time: ", dateString);
}

function onOk(value) {
  console.log("onOk: ", value);
}

ReactDOM.render(
  <div>
    <Row>
      <Col span={8}>
        <DatePicker
          open
          className="my-class"
          onChange={onChange}
          onOk={onOk}
          format="MMMM"
        />
      </Col>
      <Col span={2} offset={6}>
        <input value={null} />
      </Col>
    </Row>
  </div>,
  document.getElementById("container")
);

【问题讨论】:

    标签: javascript reactjs momentjs antd


    【解决方案1】:

    你不能,DatePicker format 属性是指格式化选择器占位符,而不是内部下拉标题。

    // Formats the date placeholder
    <DatePicker onChange={onChange} onOk={onOk} format={'YYYY-MMMM-DD'} />
    

    最接近的解决方案是实现您的选择器并根据需要呈现 Calendar 标头。

    official example for customizing Calendar header,您可以更改月份显示:

    // From
    months.push(localeData.monthsShort(current));
    // To
    months.push(localeData.months(current))
    

    查看examples

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-10-15
    • 1970-01-01
    • 1970-01-01
    • 2023-04-08
    • 1970-01-01
    • 1970-01-01
    • 2016-07-01
    相关资源
    最近更新 更多