How to get current time in python and break up into year, month, day, hour, minute?

后端 未结 11 1106
故里飘歌
故里飘歌 2020-11-28 01:18

I would like to get the current time in Python and assign them into variables like year, month, day, hour, minute

11条回答
  •  佛祖请我去吃肉
    2020-11-28 02:17

    By unpacking timetuple of datetime object, you should get what you want:

    from datetime import datetime
    
    n = datetime.now()
    t = n.timetuple()
    y, m, d, h, min, sec, wd, yd, i = t
    

提交回复
热议问题