Last active
December 18, 2015 15:29
-
-
Save rike422/5805050 to your computer and use it in GitHub Desktop.
jsでrailsの日付拡張っぽく日付取得するやつ(未テスト)タイムゾーン回り怪しい
This file contains hidden or 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.prototype.ago = function() { | |
var result, addSec, gap; | |
result = new Date(); | |
addSec = this.valueOf() * 86400000; | |
gap = dt.setTime(Date.now() - addSec); | |
result.setTime(gap); | |
return dt; | |
} | |
Number.prototype.since = function() { | |
var result, addSec, gap; | |
result = new Date(); | |
addSec = this.valueOf() * 86400000; | |
gap = dt.setTime(Date.now() + addSec); | |
result.setTime(gap); | |
return dt; | |
} | |
//一日前 | |
(1).ago(); | |
//一日後 というかdays_agoだった | |
(1).since(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment