Skip to content

Instantly share code, notes, and snippets.

@nedludd0
Created October 21, 2020 07:15
Show Gist options
  • Select an option

  • Save nedludd0/fc3e622afaf8b90c616daebe92b4bad9 to your computer and use it in GitHub Desktop.

Select an option

Save nedludd0/fc3e622afaf8b90c616daebe92b4bad9 to your computer and use it in GitHub Desktop.
small time utilities
from datetime import datetime
from datetime import timedelta
from pytz import timezone
import time
# My Default Timezone
def default_timezone():
_tz = timezone('Europe/Rome')
return(_tz)
# Now Time with Formatter or not
def my_time_now(_what_format = False):
_my_timezone = default_timezone()
if not _what_format:
_now = datetime.now(_my_timezone)
else:
_now = datetime.now(_my_timezone).strftime("%Y-%m-%d %H:%M:%S")
return(_now)
# TimeStamp milliseconds Formatter
def timestamp_formatter(_date):
_my_timezone = default_timezone()
_my_date = datetime.fromtimestamp(_date/1000, _my_timezone).strftime('%Y-%m-%d %H:%M:%S')
return(_my_date)
# Convert seconds to hh:mm:ss
def convert_seconds_to_hhmmss(_seconds):
_readable_time = None
_readable_time = str(timedelta(seconds=_seconds))
return(_readable_time)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment