我有以下代码以ISO格式生成日期和时间对象:
<TextField
id="datetime-local"
name="plannedDep" // see here!
label="Next appointment"
type="datetime-local"
onChange={this.handleChange("plannedDep")}
defaultValue="2017-05-24T10:30"
className={classes.textField}
InputLabelProps={{
shrink: true
}}
/>
'2018-09-05T14:09'
如何在不使用正则表达式的情况下从此字符串中检索from date time import datetime
datetime.now().strftime("%Y-%m.%dT%H:%M")
,month
,month day
和weekday
?
答案 0 :(得分:1)
尝试一下
import datetime
string = "19 Nov 2015 18:45:00.000"
date = datetime.datetime.strptime(string, "%d %b %Y %H:%M:%S.%f")
print(date.year)
print(date.month)
print(date.day)
print(date.hour)
print(date.minute)
print(date.second)