def datetime2timestamp(dt, default_timezone=None):
 epoch = datetime.datetime(1970, 1, 1)
 if (dt.tzinfo is None):
  if (default_timezone is None):
   default_timezone = tzutc()
  dt = dt.replace(tzinfo=default_timezone)
 d = ((dt.replace(tzinfo=None) - dt.utcoffset()) - epoch)
 if hasattr(d, 'total_seconds'):
  return d.total_seconds()
 return ((d.microseconds + ((d.seconds + ((d.days * 24) * 3600)) * (10 ** 6))) / (10 ** 6))

def datetime2timestamp ( dt , default_timezone = None ) : epoch = datetime . datetime ( 1970 , 1 , 1 ) if ( dt . tzinfo is None ) : if ( default_timezone is None ) : default_timezone = tzutc ( ) dt = dt . replace ( tzinfo = default_timezone ) d = ( ( dt . replace ( tzinfo = None ) - dt . utcoffset ( ) ) - epoch ) if hasattr ( d , 'total_seconds' ) : return d . total_seconds ( ) return ( ( d . microseconds + ( ( d . seconds + ( ( d . days * 24 ) * 3600 ) ) * ( 10 ** 6 ) ) ) / ( 10 ** 6 ) )
calculate the timestamp based on the given datetime instance .