Skip to content

Instantly share code, notes, and snippets.

@linus-amg
Last active August 29, 2015 01:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linus-amg/f600a2d7c833582d7f57 to your computer and use it in GitHub Desktop.
Save linus-amg/f600a2d7c833582d7f57 to your computer and use it in GitHub Desktop.
new Date() .time() .unix_timestamp() and Number.pad() methods !!
Number::pad = (len) ->
return (new Array(len + 1).join('0') + @).slice(-len)
Date::time = ->
returnValue = ''
returnValue += @getHours().pad(2) + ':'
returnValue += @getMinutes().pad(2) + ':'
returnValue += @getSeconds().pad(2)
return returnValue
Date::unix_timestamp = ->
ms = @getTime()
s = Math.floor(ms/1000) # or String(s/1000).split('.')[0]
return s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment