code: def _dt_to_epoch(dt):
          
          try:
              epoch = dt.timestamp()
          except AttributeError:  # py2
              epoch = (dt - datetime(1970, 1, 1)).total_seconds()
          return epoch
docs: Convert datetime to epoch seconds.