Formatting date string in Python for dates prior to 1900?

后端 未结 4 1824
梦谈多话
梦谈多话 2020-12-21 07:00

Can anyone explain the best way to format a date time string in Python where the date value is prior to the year 1900? strftime requires dates later than 1900.<

4条回答
  •  旧时难觅i
    2020-12-21 07:32

    Just for fun, I endend up with this solution.

    a = datetime.datetime(1322, 10, 10)
    # %Y%m%d
    ''.join(map(lambda x: '{:02}'.format(getattr(a, x)), ('year', 'month', 'day')))
    # %Y-%m-%d
    '-'.join(map(lambda x: '{:02}'.format(getattr(a, x)), ('year', 'month', 'day')))
    # %Y%m%d%H%M%S
    ''.join(map(lambda x: '{:02}'.format(getattr(a, x)), ('year', 'month', 'day', 'hour', 'minute', 'second')))
    

提交回复
热议问题