title: python2.7: How do I convert datetime.timedelta to an int?
body: <p>I wrote a python function to get the number of milliseconds since 1970-01-01:</p>
  
  <pre><code>def TimestampMillisec64():
      datetime_ = (datetime.datetime.utcnow() - datetime.datetime(1970, 1, 1))
  
      time_ = datetime_ * 1000
  
      return int(time_) # &lt;-- TypeError: int() argument must be a string or a number, not 'datetime.timedelta'
  </code></pre>
  
  <p>Getting an error:</p>
  
  <pre><code>TypeError: int() argument must be a string or a number, not 'datetime.timedelta'
  </code></pre>
  
  <p>How do I convert datetime.timedelta to an int in python 2.7?</p>
  
  <pre><code>TypeError: int() argument must be a string or a number, not 'datetime.timedelta'
  
  Traceback (most recent call last)
  File "/Users/user/company/istio/istio/samples/bookinfo/src/productpage/venv/lib/python2.7/site-packages/flask/app.py", line 1997, in __call__
  return self.wsgi_app(environ, start_response)
  File "/Users/user/company/istio/istio/samples/bookinfo/src/productpage/venv/lib/python2.7/site-packages/flask/app.py", line 1985, in wsgi_app
  response = self.handle_exception(e)
  File "/Users/user/company/istio/istio/samples/bookinfo/src/productpage/venv/lib/python2.7/site-packages/flask/app.py", line 1540, in handle_exception
  reraise(exc_type, exc_value, tb)
  File "/Users/user/company/istio/istio/samples/bookinfo/src/productpage/venv/lib/python2.7/site-packages/flask/app.py", line 1982, in wsgi_app
  response = self.full_dispatch_request()
  File "/Users/user/company/istio/istio/samples/bookinfo/src/productpage/venv/lib/python2.7/site-packages/flask/app.py", line 1614, in full_dispatch_request
  rv = self.handle_user_exception(e)
  File "/Users/user/company/istio/istio/samples/bookinfo/src/productpage/venv/lib/python2.7/site-packages/flask/app.py", line 1517, in handle_user_exception
  reraise(exc_type, exc_value, tb)
  File "/Users/user/company/istio/istio/samples/bookinfo/src/productpage/venv/lib/python2.7/site-packages/flask/app.py", line 1612, in full_dispatch_request
  rv = self.dispatch_request()
  File "/Users/user/company/istio/istio/samples/bookinfo/src/productpage/venv/lib/python2.7/site-packages/flask/app.py", line 1598, in dispatch_request
  return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/user/company/istio/istio/samples/bookinfo/src/productpage/productpage.py", line 277, in responseTimeApi
  millis = TimestampMillisec64()
  File "/Users/user/company/istio/istio/samples/bookinfo/src/productpage/productpage.py", line 303, in TimestampMillisec64
  return int(time_)
  TypeError: int() argument must be a string or a number, not 'datetime.timedelta'
  The debugger caught an exception in your WSGI application. You can now look at the traceback which led to the error.
  To switch between the interactive traceback and the plaintext one, you can click on the "Traceback" headline. From the text traceback you can also create a paste of it. For code execution mouse-over the frame you want to debug and click on the console icon on the right side.
  
  You can execute arbitrary Python code in the stack frames and there are some extra helpers available for introspection:
  
  dump() shows all variables in the frame
  dump(obj) dumps all that's known about the object
  Brought to you by DON'T PANIC, your friendly Werkzeug powered traceback interpreter.
  </code></pre>