Python's way of calculating the date after N days

  • 2020-04-02 14:47:19
  • OfStack

This example shows how python calculates a date after N days. Share with you for your reference. The details are as follows:

Python calculates the date after N days, so you can write it as a function, you can get the date after a few days


#! /usr/bin/env python
#coding=utf-8
import time
import datetime
d1 = datetime.datetime.now()
d3 = d1 + datetime.timedelta(days =10)
print str(d3)
print d3.ctime()

The output results are as follows:


2015-02-18 16:49:28.362000
Fri Feb 18 16:49:28 2015

I hope this article has helped you with your Python programming.


Related articles: