-
-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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
DatePicker onChange 需要得到 format 后的值 #1104
Comments
返回原生 Date 对象的初衷是想要去掉 https://github.com/yiminghe/gregorian-calendar/ 的影响,让大家可以选用 moment 这样的库二次处理,也方便后续可能的底层重构。 现在看来确实有些麻烦,1.0 之后改为和 http://ant.design/components/calendar/#api 一样的方式,统一返回 GregorianCalendar 对象好了。
|
好像不用修改也可以,现在是这样做的: {
onChange: function(date){
var GregorianCalendarFormat = require('gregorian-calendar-format');
var GregorianCalendar = require('gregorian-calendar');
var gregorianCalendar = new GregorianCalendar(this.props.locale || require('gregorian-calendar/lib/locale/zh_CN'));
var df = new GregorianCalendarFormat(this.props.format || 'yyyy-MM-dd');
gregorianCalendar.setTime(date);
var dateString = df.format(gregorianCalendar);
console.log(dateString)
}
} |
目前也可以直接用 Date 原生方法来得到 String 。
|
我用的timepicker,也有这样的需求,希望得到输入框中的字符串 |
date.toLocaleDateString() 肯定不行啊,这个跟输入框的字符串不一致。 |
+1 |
先补充第二个参数如何? onChange(date, text) {
} |
嗯 |
原生的 input[type=date] 的日期类型输入框是不允许修改 format 的。
|
This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread. |
现在的 DatePick onChange 只能得到 Date 类型的值,要是想得到 format 后的值还需要自己再用第三款库进行 format,这样就没有办法保证跟组件 format 一样的值。
是否可以:
The text was updated successfully, but these errors were encountered: