4

I'm struggling to convert a seconds timestamp to a date because I keep receiving these errot messages that I do not fully understand.

secs = 1673715600000

I want this to return the corresponding date of this timestamp.

So I tried the following:

(1)

secstodate = date.fromtimestamp(secs).strftime("%A, %B %d, %Y %I:%M:%S")

Output:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 22] Invalid argument

(2)

secstodate2= time.strftime('%m/%d/%y %H:%M:%S', time.gmtime(secs))

Output:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 22] Invalid argument

I find this strange, because this seems to be the exact same syntax that im seeing used elsewhere on stack overflow.

What am I doing wrong?

FObersteiner
  • 22,500
  • 8
  • 42
  • 72
spmf1694
  • 41
  • 3
  • 1
    In order to answer this, please give more information regarding your code (the error does not seem to be from the date time but rather some other part of your code) and perhaps where you are trying to run it (in the terminal? via a run button of an editor?). These information are needed in this case to debug this error. – Ping34 Jan 22 '23 at 16:22
  • I know I'm not supposed to give answers in the comments, but since this question is closed: Your `secs` variable contains milliseconds, rather than seconds. If you convert it to actually be seconds (so divide it by 1000) you'll end up with 'Saturday, January 14, 2023 12:00:00', which I assume is the result you are looking for :) – Robin van den Hurk Jul 19 '23 at 08:53

0 Answers0