Skip to content

Instantly share code, notes, and snippets.

@CaptainYarb
Created July 21, 2016 05:02
Show Gist options
  • Save CaptainYarb/fc8604e32e85d265828b6f636715dc9a to your computer and use it in GitHub Desktop.
Save CaptainYarb/fc8604e32e85d265828b6f636715dc9a to your computer and use it in GitHub Desktop.
Setting Dates in Javascript - The Test
var timestamp = '2000/01/01 00:00:00',
dates = [],
total = 1000,
i = 0,
pattern = new RegExp('([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2})\.([0-9]{1,2})');
var makeNiceDate = function(date, len){ // make sure our date formats are "01-01-2000" rather than "1-1-2000"
len = len || 2;
return String("0"+date).slice(-len);
}
while(i < total){
var d = new Date(timestamp);
d.setDate(i);
dates.push("" + makeNiceDate(d.getFullYear(), 4) + "-" + makeNiceDate(d.getMonth()+1) + "-" + makeNiceDate(d.getDate()) + " " + makeNiceDate(d.getHours()) + ":" + makeNiceDate(d.getMinutes()) + "." + makeNiceDate(d.getSeconds()));
i++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment