Jump to content

converting seconds to epoch time and back.


Recommended Posts

I am using the Table Import SOP to convert from human readable time to seconds... 

 

2015-05-13 11:24:17

 

This converts using the convert date to seconds menu flydown in the SOP as:

 

 1431534257

 

Which is great, but I now need to go back the other way?  is there a way to format a string sequence back as a human readable date?

Link to comment
Share on other sites

The short answer is yes. The long answer is this... I'm getting back '2015-05-13 11:24:17' so the numbers seem sane.

 

https://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior

from datetime import datetime
foo = datetime.fromtimestamp(1431534257)
readable = foo.strftime('%Y-%m-%d %H:%M:%S')
print readable
Edited by lukeiamyourfather
Link to comment
Share on other sites

Great this looks really promising.  Now I only have to apply this. I'm not so good in python, this is what I got and its not quite working.  What I would like is ideally to read the timeStamp from an attribute, and convert to the readable date, and output as a string attribute. I created both attributes before the pythonSOP.

node = hou.pwd()
geo = node.geometry()

# Add code to modify contents of geo.
for point in geo.points():
    ts = point.attribValue("timeStamp")
    foo = datetime.fromtimestamp(ts)
    readable = foo.strftime('%Y-%m-%d %H:%M:%S')
    point.setAttribValue("Date", readable)  

TimeStamp_V1.hip

Link to comment
Share on other sites

ok really dumb error... forgot to import datetime  :blush:

 

now its working

node = hou.pwd()
geo = node.geometry()
from datetime import datetime

# Add code to modify contents of geo.
for point in geo.points():
    ts = point.attribValue("timeStamp")
    foo = datetime.fromtimestamp(ts)
    readable = foo.strftime('%Y-%m-%d %H:%M:%S')
    point.setAttribValue("Date", readable)    

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...