You should use timestamps as you can calculate with them.
This is how you get the current timestamp:
Math.round(new Date().getTime() / 1000)
Please note that this the computers local time.
Now you can get the timestamp 24 hours ago like this:
var ts = Math.round(new Date().getTime() / 1000); var tsYesterday = ts - (24 * 3600);
Please see this fiddle: http://jsfiddle.net/Mjm7V/
As Nick correctly pointed out,
Just subtract the amount of milliseconds in 24 hours from the date:
new Date (Date.UTC(2012, 5, 17, 22, 34) - 24 * 3600 * 1000)
24 hours ago:
new Date(Date.now() - 86400 * 1000).toISOString()
Date.now()returns seconds since epoch.
86400seconds in a day times
1000to convert to milliseconds
This is actually fairly simple:
var yesterday = new Date(new Date().getTime() - (24 * 60 * 60 * 1000));
Simply construct a new
Date with the value of the current timestamp minus 24 hours.
(24 hours multiplied by 60 minutes in each hour multiplied by 60 seconds in each minute multiplied by 1000 milliseconds in each second)
- How to change time in hours on HighChart xAxis from Military to Standard time?
- Relative time in Highstocks chart
- Strange character in the Highstock source code
- HighChart Time Series hours starting at 4pm
- Setting the length of the X-Axis of a Highchart to be 24 hours from time of first data point with less than 24 hours of data to display
- how to display the last five hours time from current time(hh:mm ) 12 hour format in high charts?
- highchart scatter with 24 hours time on y axis and the day of the transaction on x axis
- Displaying hours and minutes on x-axis with Highcharts
More Query from same tag
- Highcharts Polar, edit onmouseover label
- How do I calculate the sum of the points in a HighChart after I edit it
- Total of values in HighCharts Pie Chart
- Highcharts Map not Zooming Properly
- How can I get highstock zoom infomation?
- Highcharts - setting the yAxis title dynamically
- How to translate label "Week x"?
- HighCharts - hiding series based on page?
- Highcharts: how to optimize auto-scaling so that columns make better use of the available height
- How to Cache DOM Variable in jQuery
- How to generate Highcharts JS live data graphs from data on other website?
- Scatter Bubble chart without Y axis in HighChart
- highchart export button not show
- Highstock - Can't update using value from file, data type?
- How to create scrollbar in Highcharts
- Multiple series of data in Highcharts but second line graph is displayed squashed?
- ES6 avoid that/self
- Highchart.Chart() on Marionette App
- In Highcharts, for a 3D chart, are we able to set up labels of the z-axis?
- plot bands in x-axis is not working on time
- parsing JSON data to render high chart graph
- Highcharts - data day sum one day ahead
- Highchart strange behavior of Range selector text boxes.
- Vue Highcharts display graph for each user after routing
- Highcharts: get an event before drilldown?
- How would I add a padding to the plot area in HighCharts (HighStock) to pad the border?
- style highmaps mapbubbles onclick
- Restrict mouseover area for a column to its own shape vs. surrounding area