Mark Henry
Mark Henry

Reputation: 2699

jquery Flot timestamp to week numer

I use flot and want to display timestamp as week numbers. e.g. 1291590000000 is week 1 the timestamp is already representing the very beginning of a week. How does one do that.

Upvotes: 0

Views: 697

Answers (1)

Mutation Person
Mutation Person

Reputation: 30498

Not entirely sue what you mean.

the FLOT Documentation states:

The time series support in Flot is based on Javascript timestamps, i.e. everywhere a time value is expected or handed over, a Javascript timestamp number is used. This is a number, not a Date object. A Javascript timestamp is the number of milliseconds since January 1, 1970 00:00:00 UTC. This is almost the same as Unix timestamps, except it's in milliseconds, so remember to multiply by 1000!

So, to get the weeks, divide the number by 604800000 (1000*60*60*24*7), and then round. If 1291590000000 is your starting point then substract it your current number (remembering to add 1 if you are treating this as week '1')

var start = 1291590000000;
var sometime = 1292590000000;
var weekMillis = 604800000
var weeks = 1 + Math.round((sometime-start)/weekMillis);
alert(weeks );

Mocked up at: http://jsfiddle.net/6XDKT/1/

Upvotes: 3

Related Questions