[Python Patterns] Get time in an orderly way

Using a module called Arrow to export time in a dictionary. I love the simplicity of Arrow and use it whenever I can.

Using a module called Arrow to export time in a dictionary. I love the simplicity of Arrow and use it whenever I can.

https://arrow.readthedocs.io/en/latest/

import arrow

def get_time():
    """ Gets time and returns a dictionary """
    utc = arrow.utcnow()
    local = utc.to('US/Pacific')
    # Get UNIX Epoc
    post_time = local.timestamp
    # Get human time
    display_time = local.format('YYYY-MM-DD HH:mm')
    time_dict = {'post_time': post_time, 'display_time': display_time}
    print(time_dict)
    return time_dict

Output:

>>> get_time()
{'post_time': 1577473040, 'display_time': '2019-12-27 10:57'}

My blog posts tagged with "Python Patterns" are designed to be a quick look reference for some Python code snippets I use a lot.  They are written to be a quick starting point for future projects so I do not need to type as much.