text: 29491/how-to-convert-datetime-date-to-utc-timestamp-in-python
  I need to convert date to UTC timestamps to be used inside Javascript.
  The following code does not work:
  >>> d = datetime.date(2018,10,31)
  >>> datetime.datetime.utcfromtimestamp(time.mktime(d.timetuple()))
  datetime.datetime(2018, 10, 31, 23, 0)
  Converting the date object first to datetime also does not help. I tried the example at this link from, but:
  from pytz import utc, timezone
  from datetime import datetime
  from time import mktime
  input_date = datetime(year=2011, month=1, day=15)
  and now either:
  mktime(utc.localize(input_date).utctimetuple())
  or
  mktime(timezone('US/Eastern').localize(input_date).utctimetuple())
  does work.
  From the docs for datetime.utcfromtimestamp():
  There is no method to obtain the timestamp from a datetime instance, but POSIX timestamp corresponding to a datetime instance dt can be easily calculated as follows. For a naive dt:
  There is no method to obtain the timestamp from a datetime instance, but POSIX timestamp corresponding to a datetime instance dt can be easily calculated as follows. For a naive dt:
  timestamp = (dt - datetime(1970, 1, 1)) / timedelta(seconds=1)
  And for an aware dt:
  And for an aware dt:
  timestamp = (dt - datetime(1970,1,1, tzinfo=timezone.utc)) / timedelta(seconds=1)
  Hello @ pagarsach,
  You can convert a string to ...READ MORE
  g1 here is a DataFrame. It has a hierarchical index, ...READ MORE
  The parse() function in dateutil can't handle ...READ MORE
  If you are using Python 3.x then ...READ MORE
  suppose you have a string with a ...READ MORE
  You can also use the random library's ...READ MORE
  Syntax :
  list. count(value)
  Code:
  colors = ['red', 'green', ...READ MORE
  can you give an example using a ...READ MORE
  Use this :-
  >>> datetime.datetime.strptime('2405201 ...READ MORE
  what you are looking for is a ...READ MORE
  OR
  Already have an account? Sign in.