How can I convert a int type to time type
<p>I want to convert 20161017(int type) to 20161017(time type)</p>

<p>I try</p>

<pre><code>import time
a=20161017

b = time.strftime('%Y%m%d',a)

print(b)
</code></pre>

<p>but It cannot work</p>

<p>additional question</p>

<p>in int type, i use 20161017 - 10000 = 20151017
how can i do this in 20161017(time type)?</p>

<p>strptime takes string as argument. So you have to first convert your <code>a</code> to string. And you should also use str<strong>p</strong>time instead of str<strong>f</strong>time</p>

<pre><code>b = time.strptime(str(a), '%Y%m%d')
</code></pre>

<p>as for your additional question. There is <code>dateutil.relativedelta</code> for that.</p>

<pre><code>from dateutil.relativedelta import relativedelta
c = b - relativedelta(year=1)
</code></pre>

python time