Skip to content

Instantly share code, notes, and snippets.

@rike422
Last active December 18, 2015 15:29
Show Gist options
  • Save rike422/5805050 to your computer and use it in GitHub Desktop.
Save rike422/5805050 to your computer and use it in GitHub Desktop.
jsでrailsの日付拡張っぽく日付取得するやつ(未テスト)タイムゾーン回り怪しい
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