【发布时间】:2021-12-15 07:35:30
【问题描述】:
我想将默认时间设置为比当前时间晚 4 小时,所以如果是 2021 年 10 月 31 日凌晨 3:00,则默认时间应显示为 2021 年 10 月 31 日凌晨 4:00 在 2021 年 10 月 31 日晚上 10:00 这样的时间里,它应该显示 2021 年 11 月 1 日凌晨 2:00
我尝试将当前时间加到 4,但它会破坏夜间时间。
const currentDate = new Date();
const dateTime = `${currentDate.getFullYear()}-${currentDate.getMonth() + 1}-${currentDate.getDate()}T${
currentDate.getHours() + 3
}:${currentDate.getMinutes()}`;
<TextField
id="datetime-local"
type="datetime-local"
defaultValue={`${dateTime}`}
InputLabelProps={{
shrink: true,
}}
InputProps={{ inputProps: { min: `${dateTime}` } }}
onChange={handleChange}
/>
</div>
【问题讨论】:
标签: reactjs datetime datepicker material-ui