Print time value in python
Question: I am trying to print the contents of my dictionary with actual time values
(for example, '6:00 AM') from my workbook. I get a different time format when
I print from 'TimeSheet' than I do 'From'. How can I get the actual time value
to print.

[![enter image description
here](http://i.stack.imgur.com/XPHRA.jpg)](http://i.stack.imgur.com/XPHRA.jpg)

    
    
    import openpyxl
    
    wb = openpyxl.load_workbook('Sample.xlsx')
    
    sheet = wb.get_sheet_by_name('Sheet2')
    for i in range(1, 57):
       From = sheet.cell(row=i, column=1).value
       To = sheet.cell(row=i, column=2).value
       Activity = sheet.cell(row=i, column=3).value
       TimeSheet = {'From': From, 'To': To, 'Activity': Activity}
       print(TimeSheet)
    

Current output:

    
    
    {'Activity': 'ACTIVITY', 'From': 'FROM', 'To': 'TO'}
    {'Activity': None, 'From': datetime.time(6, 0), 'To': datetime.time(6, 15)}
    {'Activity': None, 'From': datetime.time(6, 15), 'To': datetime.time(6, 30)}
    {'Activity': None, 'From': datetime.time(6, 30), 'To': datetime.time(6, 45)}
    {'Activity': None, 'From': datetime.time(6, 45), 'To': datetime.time(7, 0)}
    {'Activity': None, 'From': datetime.time(7, 0), 'To': datetime.time(7, 15)}
    {'Activity': None, 'From': datetime.time(7, 15), 'To': datetime.time(7, 30)}
    {'Activity': None, 'From': datetime.time(7, 30), 'To': datetime.time(7, 45)}
    


Answer: You're looking for `strftime` (string-format-time).

    
    
    >>> from datetime import datetime
    
    >>> datetime.now()
    datetime.datetime(2016, 6, 14, 17, 24, 27, 735835)
    
    >>> datetime.now().strftime("%Y %m %d")
    '2016 06 14'
    

The [python
documentation](https://docs.python.org/2/library/datetime.html#strftime-
strptime-behavior) on the subject is pretty extensive, and there's also this
[convenient reference table](http://strftime.org/) for the format language.

