我制作的程序只会在明天打印出一套优惠,我想明确指出明天的日期,我这样做了:
Tomorrow = datetime.date.today() + datetime.timedelta(days=1)
这给出了outpu:
2016-04-11
正如你所看到的,它确实给了明天像计划的日期,除了它以YYYY-MM-DD格式,这是我的问题。有没有办法以DD-MM-YYYY格式打印明天日期? 干杯
答案 0 :(得分:6)
Tomorrow.strftime('%d-%m-%Y')
应该排序你。希望有所帮助。
答案 1 :(得分:-2)
以下是我的回答:
dt = "9'/30'/2017 16:40:09" # assume dt is the datetime variable
date, space, time = dt.partition(' ') # use dt.partition to separate date and time by space
mm, slash, str = date.partition('/') # use date.partition to separate mm and str by slash, mm is found
dd, slash, yyyy = str.partition('/') # use str.partition to separate dd and yyyy by slash, dd and yyyy are found
new_date = dd + '/' + mm + '/' + yyyy # set new_date in any desired format
# new_date = 30/9/2017