2

I have string like this 2019-06-13 23:37:02.284175. I would like to convert this string to unix time epoch. How can I convert this string to unix timestamp using python??

0

2 Answers 2

2

In Python 3.7+ you can do this using datetime.datetime.fromisoformat:

import datetime

print(datetime.datetime.fromisoformat("2019-06-13 23:37:02.284175").timestamp())

Output:

1560469022.284175
Sign up to request clarification or add additional context in comments.

Comments

2
from datetime import datetime

string_date = '2019-06-13 23:37:02.284175'
date_format = '%Y-%m-%d %H:%M:%S.%f'
epoch_time = datetime(1970, 1, 1)
print((datetime.strptime(string_date, date_format) - epoch_time).total_seconds())
# 1560469022.284175

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.