Reputation: 307
I'm making a JSON call to COSM (now Xively) so it will return data that I can plot with Highchart's highstock chart. See: jsfiddle.net/T7D5U/2/
Currently the start and end date are hard coded like this:
$.getJSON('http://api.xively.com/v2/feeds/4038/datastreams/9.json?start=2013-05-01T00:00:00Z&end=2013-05-19T23:00:00Z&interval=3600?key=dNSiSvXZtR6QBUqbzll4CCgnngGSAKxIQVFSeXBneGpqWT0g', function(data) {
I want the start and end dates to be dynamic. I want the end date and time to be now. If now was May 19, 2013 2:30 PM, it would be formatted like this:
end=2013-05-19T14:30:00Z
And I'd like the start time to be now minus 10 days, this can be rounded to the day. So the start time would look like this:
start=2013-05-09T00:00:00Z
BTW, I'm not familiar with JavaScript (just C).
Also, when I try an put a jsfiddle link in stackoverflow post, I get an error that says "Links to jsfiddle.net must be accompanied by code." I'm confused by this; I don't know what I'm supposed to do.
Upvotes: 0
Views: 398
Reputation: 537
I will do it that way :
// Set end to current date and time on client
var end = new Date();
// Copy end date and assign to start
var start = new Date(+end);
// Set date of start to 10 days ago
start.setDate(start.getDate() - 10);
alert(start.toISOString());
Upvotes: 0