today, when using Python to get a date, use the date.strftime ('%y.%m.%d. %h%i ') to format the obtained date if the month is less than 10, a leading 0 appears. gets the date format such as: 2017.03.24.0510 so there will be a 0 in front of the month 3, but at this point we do not want this 0, so Baidu a bit, found are using%-d, but in the Pycharm run when the direct collapse, so can only find his way, found that there is a way "Date.timetuple (): Returns the Time.struct_time object corresponding to the date;" This method returns a struct, as follows:
Time.struct_time (tm_year=2017, tm_mon=3, tm_mday=24, tm_hour=19, tm_min=37, tm_sec=3, tm_wday=4, tm_yday=83, tm_isdst= -1), the number in this struct does not contain its leading 0, so it can be spliced using its struct body. So The code is as follows :
Time = Datetime.datetime.now (). Timetuple ()
Versioninfo = str (time.tm_year) + '. ' + str (time.tm_mon) + '. ' + str (time.tm_mday) + '. ' + str (time.tm_hour) + str (time.tm _min)
Datetime.datetime.now (). Timetuple () returns a struct in which the corresponding data can be obtained by means of the method tm_xxx, which is only used for stitching.
The value of the obtained versioninfo is: ' 2017.3.24.1937 ', which is exactly what I want. Haha, it's done.
Python removes the leading 0 of the date