VolleyBall Player
VolleyBall Player

Reputation: 710

Convert Date to jQuery Flot time

I have json being returned from my WebAPI.

[{"Total":7,"ActivityType":1,"TimeStamp":"2013-03-16T00:16:00.387","Id":1,"State":"Alabama"},{"Total":4,"ActivityType":1,"TimeStamp":"2013-03-16T00:31:00.41","Id":1,"State":"Alabama"}]

Flot Requires data like this.

var d1 = [[1262818800,100],[1262732400,100],[1262646000,100]];

I need to convert the timestamp to ticks or whatever in javascript so that I can use to plot my graph. I would appreciate if anyone could help me. A jsFiddle example would help.

Upvotes: 3

Views: 1962

Answers (2)

Jashwant
Jashwant

Reputation: 29005

var arr = [{
    "Total": 7,
    "ActivityType": 1,
    "TimeStamp": "2013-03-16T00:16:00.387",
    "Id": 1,
    "State": "Alabama"
}, {
    "Total": 4,
    "ActivityType": 1,
    "TimeStamp": "2013-03-16T00:31:00.41",
    "Id": 1,
    "State": "Alabama"
}];


var d1 = [];
for (var i = 0, len = arr.length; i < len; i++ ) {
    var t = [new Date(arr[i].TimeStamp).getTime() / 1000,100]
    d1.push(t);
}

Upvotes: 0

dfsq
dfsq

Reputation: 193261

Try this:

+new Date('2013-03-16T00:16:00.387') / 1000 // 1363392960.387

Upvotes: 1

Related Questions