通过使用React,我已经使用moment和react-datepicker库设置了DatePicker组件,并将使用今天的日期计算出的初始日期值传递给MM-DD-YYYY格式。
当我尝试加载时,出现此错误行:
抛出新的RangeError('Invalid time value'); 将系统时区中的日期转换为UTC + 00:00时区中的同一日期。这样可以确保在实现UTC功能时,语言环境将与它们兼容。
DatePicker组件:
class DatePicker extends Component {
render() {
return (
// <input type="date"
// className={this.props.className + " myInput"}
// placeholder={this.props.placeholder}
// onChange={this.props.onChange}
// value={this.props.value}
// />
<DatePicker2
dateFormat="DD MMM YYYY"
className={this.props.className + " myInput"}
selected={moment(this.props.value)}
onChange={this.props.onChange}
readOnly={true}
/>
);
}
}
export default DatePicker;
我的问题是:如何将系统时区中的日期转换为UTC + 00:00时区中的相同日期(假设这是解决方案,但是如果不能解决,该如何解决呢?
答案 0 :(得分:0)
要重新格式化日期,可以使用:
moment(this.props.value).format("YYYY-MM-DD HH:mm Z");