Created
September 4, 2011 22:17
-
-
Save ChillyBwoy/1193619 to your computer and use it in GitHub Desktop.
JavaScript Date shift
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
var shiftDate = function(date, what, count) { | |
var proc1 = 'get' + what, | |
proc2 = 'set' + what; | |
var value = Date.prototype[proc1].call(date); | |
Date.prototype[proc2].call(date, value + count); | |
return date; | |
} | |
console.log(shiftDate(new Date, 'Date', -21)); | |
console.log(shiftDate(new Date, 'Date', 42)); | |
console.log(shiftDate(new Date, 'Month', -4)); | |
console.log(shiftDate(new Date, 'FullYear', 10)); |
mick62
commented
May 17, 2021
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment