score:31
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/
Edit:
As Nick correctly pointed out, Date#getTime
returns the UTC timestamp (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTime)
score:2
Just subtract the amount of milliseconds in 24 hours from the date:
new Date (Date.UTC(2012, 5, 17, 22, 34) - 24 * 3600 * 1000)
score:6
24 hours ago:
new Date(Date.now() - 86400 * 1000).toISOString()
- now:
new Date().toISOString()
- outputs:
'2017-02-04T09:15:25.233Z'
Date.now()
returns seconds since epoch.- Subtract
86400
seconds in a day times1000
to convert to milliseconds - outputs:
'2017-02-03T09:14:11.789Z'
score:67
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)
Source: stackoverflow.com
Related Query
- Javascript relative time 24 hours ago etc as time
- Optimize JavaScript DrillDown code
- php: laravel slow view render time when rendering javascript for highcharts
- Convert hours and minute to millisecond using javascript or jQuery
- MySql TimeStamp and JavaScript Time
- JavaScript code inside TypeScript file .ts not working
- Date / Time problem in javascript with highcharts
- c# WPF Webbrowser with Highchart, Javascript from external source not working "An error has occurred in the script on this page"
- passing formatting JavaScript code to HighCharts with JSON
- Embed javascript code in a django template
- How to change time in hours on HighChart xAxis from Military to Standard time?
- HTML Content to Javascript Code
- Relative time in Highstocks chart
- Strange character in the Highstock source code
- HighChart Time Series hours starting at 4pm
- tool that shows javascript errors in code
- Repeating Javascript Code
- How to convert datetime to epoch time in milliseconds javascript
- 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
- Error: Data source must be a URL for refresh | console error | javascript | Highcharts
- Javascript Code not running in Wordpress Pages
- how to display the last five hours time from current time(hh:mm ) 12 hour format in high charts?
- Use django variable (array of elements from sqlite3 database) inside javascript embedded code
- 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
- Highchart series update in javascript
- JavaScript - Export Div with SVG chart + HTML as and Image
- How can I read an Excel File with JavaScript (without ActiveXObject)
- Export Highcharts to PDF (using javascript and local server - no internet connection)
- How do I dynamically change a data point in Highcharts using JavaScript
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
- Excel charting to JavaScript
- 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?
- Javascript: Adding 0 values to arrays of different sizes
- 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