Python How to Check if time is midnight and not display time if true
<p>I'm modifying our pacific time zone filter to include a time option. I don't want the time component to be shown if midnight. The only import thus far we are using is dateutil.parser. Any pointers on best solution would be appreciated! Thanks.</p>

<pre><code>def to_pacific_date_str(timestamp, format='%Y-%m-%d', time=False):
    pacific_timestamp = timestamp

    if time:
        format='%Y-%m-%d %H:%M' # 2016-10-03 00:00
    if timestamp.tzname() is None:
        # setting timezone lost when pulled from DB
        utc_timestamp = timestamp.replace(tzinfo=pytz.utc)
        # always converting to pacific timezone
        pacific_timestamp = utc_timestamp.astimezone(pytz.timezone('US/Pacific'))
    return pacific_timestamp.strftime(format)
</code></pre>

<p>To check if the time is midnight:</p>

<pre><code>from datetime import datetime
def checkIfMidnight():
    now = datetime.now()
    seconds_since_midnight = (now - now.replace(hour=0, minute=0, second=0, microsecond=0)).total_seconds()
    return seconds_since_midnight == 0
</code></pre>

python datetime timezone pytz