Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧐[问题 | question] ProFormDateTimeRangePicker 返回的值有办法获取到 dayjs 类型 而不是字符串类型的么 #11069

Closed
xuoutput opened this issue Nov 30, 2023 · 4 comments

Comments

@xuoutput
Copy link

🧐 问题描述 | Problem description

看到 antd date-picker
传入和拿到的是 dayjs[] 类型
image

而 pro 这里变为字符串了,
image
有办法拿到 dayjs 类型么, 想着直接可以用 dayjs 类型的 format 转为自己想要的格式, 而不是拿着字符串重新传入 dayjs().format()

💻 示例代码 | Sample code

https://codesandbox.io/s/ri-qi-biao-dan-forked-73dl68

🚑 其他信息 | Other information

OS:

Node:

浏览器 | browser:

@xuoutput
Copy link
Author

bump

2 similar comments
@xuoutput
Copy link
Author

bump

@xuoutput
Copy link
Author

bump

@chenshuai2144
Copy link
Collaborator

ProFormDateTimeRangePicker 返回的值是字符串类型,而不是 dayjs 类型。如果你希望获取 dayjs 类型的值,可以使用 dayjs() 方法将字符串转换为 dayjs 对象,然后再进行格式化等操作。

你可以像这样将返回的字符串转换为 dayjs 对象:

import dayjs from 'dayjs';

const range = ['2022-01-01', '2022-01-10']; // 假设这是 ProFormDateTimeRangePicker 返回的值

const rangeDayjs = range.map(date => dayjs(date));

console.log(rangeDayjs); // [dayjs object, dayjs object]

然后,你就可以使用 dayjs 对象进行各种操作了,比如使用 format 方法格式化日期:

const formattedRange = rangeDayjs.map(date => date.format('YYYY-MM-DD'));

console.log(formattedRange); // ['2022-01-01', '2022-01-10']

这样,你就可以获取到 dayjs 类型的值,并且可以使用 dayjs 提供的各种方法对日期进行操作和格式化了。

或者可以配置 ProForm 的 dateFormatter={false} 也可以关掉默认修改

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants