{"id":1038,"date":"2017-01-23T10:51:54","date_gmt":"2017-01-23T16:51:54","guid":{"rendered":"http:\/\/blog.ls-al.com\/?p=1038"},"modified":"2017-01-23T11:34:15","modified_gmt":"2017-01-23T17:34:15","slug":"date-strings-with-inconsistent-spaces","status":"publish","type":"post","link":"https:\/\/blog.ls-al.com\/date-strings-with-inconsistent-spaces\/","title":{"rendered":"Date strings with inconsistent spaces"},"content":{"rendered":"

I frequently bump into manipulating very large log files and the date input strings are formatted poorly. <\/p>\n

Couple problems for me here:
\n1. Input is like this \"Sat Feb 6 03:25:01 2016\". You can see there is a double space in front of 6. a \"06\" may have been more useful. The additional space gives python's strptime fits and I have to do something like this.
\n2. Sorting \"Sat Feb ...\" is not ideal so reformat it to something like \"2016-02-06...\" may work better down the line. Maybe in Excel or Calc.<\/p>\n

\r\nimport datetime\r\n\r\nd = 'Sat Feb  6 03:25:01 2016'\r\n#d = 'Sat Feb 19 03:25:01 2016'\r\n\r\nif d[8:9] == ' ':\r\n  new = list(d)\r\n  new[8] = '0'\r\n  d=''.join(new)\r\n\r\nprint "Useful date is: {dt}".format(dt=datetime.datetime.strptime(d,'%a %b %d %H:%M:%S %Y').strftime('%Y-%m-%d %H:%M:%S'))\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

I frequently bump into manipulating very large log files and the date input strings are formatted poorly. Couple problems for<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-1038","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/1038","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/comments?post=1038"}],"version-history":[{"count":0,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/1038\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/media?parent=1038"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/categories?post=1038"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/tags?post=1038"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}