changing the format of timestamp in python
问题 I am trying to change the timestamp from one format to another. I tried some approaches but i am not able to succeed. This is my timestamp 151005-12:07:34.917928 I would like to change it to a format like this 2015-10-05 12:07:34:917928 Thanks in Advance 回答1: Here's one way using regular expressions: import re e = '(\d{2})(\d{2})(\d{2})-(\d{2}:\d{2}:\d{2})\.(\d+)' s = '151005-12:07:34.917928' print('20{}-{}-{} {}:{}'.format(*re.search(e, s).groups())) 2015-10-05 12:07:34:917928 Here's another