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

后端 未结 11 1069
故里飘歌
故里飘歌 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条回答
  •  萌比男神i
    2020-11-28 02:02

    The datetime answer by tzaman is much cleaner, but you can do it with the original python time module:

    import time
    strings = time.strftime("%Y,%m,%d,%H,%M,%S")
    t = strings.split(',')
    numbers = [ int(x) for x in t ]
    print numbers
    

    Output:

    [2016, 3, 11, 8, 29, 47]
    

提交回复
热议问题