0

given the time in the following format Nov 30 20:48:48 +0000 2013, how can this be converted to epoch time? It will be helpful to know on how to convert epoch time to a presentable format.

Amrith Krishna
  • 2,768
  • 3
  • 31
  • 65
  • 1
    Have you tried anything yet? – lanzz Feb 25 '14 at 10:29
  • I have tried with time library. and all I know is a quick and dirty way,where i should convert each month to corresponding numerical representation with a `dict()`, and strip off the timezone and then convert it. I just wanted to know, if there is any inbuilt method to handle the same – Amrith Krishna Feb 25 '14 at 10:31

2 Answers2

1

Like this at the command-line:

date --date="Nov 30 20:48:48 +0000 2013" +"%s"
1385844528

Reverse operation:

date --date='@1385844528'
Sat Nov 30 20:48:48 GMT 2013
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • which is the module to import? I mean I am looking for a solution in python – Amrith Krishna Feb 25 '14 at 10:36
  • This is at the command-line. I guess you'd have to execute it with the subprocess module if you wanted to use the command-line tool. Maybe python has a better way - I do not know. – Mark Setchell Feb 25 '14 at 10:39
0

I have found the answer in the blog sandrotosi

import time
import calendar
stra ="Sat Nov 30 20:48:48 +0000 2013"
formata = "%a %b %d %H:%M:%S +0000 %Y"
print calendar.timegm(time.strptime(stra, formata))

Here this will give the converted time in epoch and since am using the timegm(), the time is +0000, while

mktime(), then it uses the lcoal timezone

Amrith Krishna
  • 2,768
  • 3
  • 31
  • 65