breadbox Posted May 14, 2015 Share Posted May 14, 2015 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? Quote Link to comment Share on other sites More sharing options...
lukeiamyourfather Posted May 14, 2015 Share Posted May 14, 2015 (edited) 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 May 14, 2015 by lukeiamyourfather Quote Link to comment Share on other sites More sharing options...
breadbox Posted May 14, 2015 Author Share Posted May 14, 2015 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 Quote Link to comment Share on other sites More sharing options...
breadbox Posted May 15, 2015 Author Share Posted May 15, 2015 ok really dumb error... forgot to import datetime 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) 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.