我有一个TimePicker
以这种格式返回 24 小时时间的组件:09:00
上午 9 点或12:00
下午 12 点或20:00
晚上 8 点。我的代码中的某些内容需要Date
(JSDate),因此我只想获取当前日期/时间DateTime.now()
,但从TimePicker
具有onClick
事件的组件中应用小时和分钟。我可以像这样处理那个事件:
// TimePickerValue can either be a string or JSDate
// but the TimePicker is always returning a string
const handleTimeChange = (time:TimePickerValue) => {
// this outputs a time in 24-hour format
console.log("handleTimeChange: ", time)
// I want to set the state of the parent component
// this needs to be in JSDate format so this doesn't work
// setSomeValue(time)
// Because I don't care about date, I can just use "now()" and convert
// it to a JSDate but I want the hours and minutes of the value I'm setting
// to be the time in the string being sent to this function.
setSomeValue(DateTime.now().toJSDate())
}
Luxon 可以解析“13:00”之类的内容或将其应用于现有DateTime
内容,以便覆盖其现有的hours
andminutes
吗?