I'm new to D3 and I'm trying to console.log the unix timestamps in my json file in a more readable form, such as date objects. How would I go about accessing value in the "dt" and convert that into a date object?
Here is an example of what a snippet of my json file looks like
"list": [
{
"main": {
"aqi": 2
},
"components": {
"co": 213.62,
"no": 0.98,
"no2": 6,
"o3": 85.83,
"so2": 1.89,
"pm2_5": 4.94,
"pm10": 11.6,
"nh3": 0.37
},
"dt": 1629072000
},
{
CodePudding user response:
Since this question is tagged d3.js, a D3 solution is using the specifier %s
for seconds since Unix epoch, with d3.timeParse
:
const parser = d3.timeParse("%s");
const seconds = 1629072000;
console.log(parser(seconds))
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/5.7.0/d3.min.js"></script>