Skip to content

Instantly share code, notes, and snippets.

@abdalmoez
Created January 7, 2020 11:59
Show Gist options
  • Select an option

  • Save abdalmoez/8772490c24fcda0732f599a67ad896e2 to your computer and use it in GitHub Desktop.

Select an option

Save abdalmoez/8772490c24fcda0732f599a67ad896e2 to your computer and use it in GitHub Desktop.
Python convert nano seconds to string (hour, minute, seconds, ...)
def nsToStr(nanoseconds):
h=3.6e+12
m=h/60
s=m/60
return str(int(d/h)) +':'+str(int((d%h)/m))+':'+ str(int((d%h)%m/s)) + '.' + str(int((d%h)%m%s))
@V-Derbenev-Tizbi

Copy link
Copy Markdown

d is undefined

@mkf62

mkf62 commented Nov 6, 2025

Copy link
Copy Markdown

d is supposed to be nanoseconds. Just replace d with nanoseconds and it works. Thanks @abdalmoez .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment