Skip to content

Instantly share code, notes, and snippets.

@linus-amg
Last active Aug 29, 2015
Embed
What would you like to do?
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