I have the following code:
def parse_contents(contents, filename, last_modified):
content_type, content_string = contents.split(',')
decoded = base64.b64decode(content_string)
try:
if 'csv' in filename:
# assume that the user uploaded a CSV file
df = pd.read_csv(
io.StringIO(decoded.decode('utf-8')))
elif 'xls' in filename:
# assume that the user uploaded an Excel file
df = pd.read_excel(io.BytesIO(decoded))
elif 'txt' or 'tsv' in filename:
# assume that the user uploaded a TXT file
df = pd.read_csv(io.StringIO(decoded.decode('utf-8')), delimiter = r'\s+')
except Exception as e:
print(e)
return html.Div([
'There was an error processing this file.'
])
return html.Div([
html.H5(filename,
style={'font-family' : 'Arial'}),
html.H5(datetime.datetime.fromtimestamp(last_modified),
style={'font-family' : 'Arial'}),
dash_table.DataTable(
id='table',
columns=[{'name': i, 'id': i} for i in df.columns],
data=df.to_dict('records'),
sort_action='native',
filter_action='native',
page_size= 5,
style_table={'height' : '300px',
'overflowY' : 'auto'},
style_cell={'width' : '300px',
'height' : '30px',
'textAlign' : 'left'}
),
])
When the file is uploaded, the function returns the following (among other things) on the screen:
2020-06-18T19:22:16.374000
I tried the following:
datetime.datetime.strptime(last_modified, '%Y-%m-%d %H:%M:%S.%f')
Which did not work.
What is the best way to convert the output into 06-18-2020 19:22:16.374000?
Thanks!