Last active
August 29, 2015 01:57
-
-
Save linus-amg/f600a2d7c833582d7f57 to your computer and use it in GitHub Desktop.
new Date() .time() .unix_timestamp() and Number.pad() methods !!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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