如何从DateTime字符串中检索月份,月份,星期几和小时?

时间:2019-01-13 21:25:48

标签: python datetime

我有以下代码以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") monthmonth dayweekday

1 个答案:

答案 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)

https://onlinegdb.com/S1KDCmKzN