Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/378.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在使用Javascript加载DarkSky之后格式化日期、时间和温度_Javascript_Json_Format - Fatal编程技术网

在使用Javascript加载DarkSky之后格式化日期、时间和温度

在使用Javascript加载DarkSky之后格式化日期、时间和温度,javascript,json,format,Javascript,Json,Format,我正在做我自己的项目,这是一个天气预报网站。然而,在从DarkSky加载JSON后,我对日期、时间和温度格式有一些问题。 下面是我从DarkSky获得JSON后的数据: apparentTemperatureHigh: 88.48 ​​​​ apparentTemperatureHighTime: 1527627600 ​​​​ apparentTemperatureLow: 69.66 ​​​​ apparentTemperatureLowTime: 1527674400 ​​​​ appar

我正在做我自己的项目,这是一个天气预报网站。然而,在从DarkSky加载JSON后,我对日期、时间和温度格式有一些问题。 下面是我从DarkSky获得JSON后的数据:

apparentTemperatureHigh: 88.48
​​​​
apparentTemperatureHighTime: 1527627600
​​​​
apparentTemperatureLow: 69.66
​​​​
apparentTemperatureLowTime: 1527674400
​​​​
apparentTemperatureMax: 88.48
​​​​
apparentTemperatureMaxTime: 1527627600
​​​​
apparentTemperatureMin: 68.31
​​​​
apparentTemperatureMinTime: 1527573600
​​​​
cloudCover: 0.88
​​​​
dewPoint: 68.69
​​​​
humidity: 0.83
​​​​
icon: "fog"
​​​​
moonPhase: 0.51
​​​​
ozone: 318.12
​​​​
precipIntensity: 0.0003
​​​​
precipIntensityMax: 0.0018
​​​​
precipIntensityMaxTime: 1527649200
​​​​
precipProbability: 0.15
​​​​
precipType: "rain"
​​​​
pressure: 1016.16
​​​​
summary: "Foggy in the morning."
​​​​
sunriseTime: 1527587293
​​​​
sunsetTime: 1527640035
​​​​
temperatureHigh: 84.29
​​​​
temperatureHighTime: 1527627600
​​​​
temperatureLow: 68.49
​​​​
temperatureLowTime: 1527674400
​​​​
temperatureMax: 84.29
​​​​
temperatureMaxTime: 1527627600
​​​​
temperatureMin: 67.36
​​​​
temperatureMinTime: 1527573600
​​​​
time: 1527566400
​​​​
uvIndex: 7
​​​​
uvIndexTime: 1527613200
​​​​
visibility: 6.25
​​​​
windBearing: 146
​​​​
windGust: 11.99
​​​​
windGustTime: 1527645600
​​​​
windSpeed: 2.44
因此,我不知道如何将时间(即
1527566400
转换为我可以阅读的时间。此外,我混淆了
temperatureHighTime
temperaturelowhtime

您能告诉我如何将这些值格式化为可读值吗?我将非常感谢您的帮助。

给出的时间看起来像是UNIX时间-自1970年1月1日UTC 00:00以来的秒数

大多数高级编程语言都有一个功能,可以将UNIX时间转换为更可读的值-。

const moment=require('moment')//在shell“npm i moment”中安装它
常数dateTime=力矩(,'X')
#其中“X”是秒的格式快捷方式
console.log(dateTime.format(“YY-MM-DD HH:MM:ss”)//2019-04-13 10:56:12

对于celcius v farenheit,请更改单位。对于pass
.units('ci')
,请更改科学单位。

谢谢@hitecherik。正如你所说。如果你知道温度,你能告诉我吗?别担心,温度看起来像是华氏温度。哎呀。我误读了温度。谢谢@hitecherik。
const moment=require('moment')   // in the shell 'npm i moment' to install it

const dateTime=moment(<unix time in seconds>, 'X')

# Where 'X' is the format shortcut for seconds

console.log(dateTime.format("YY-MM-DD HH:mm:ss")    // 2019-04-13 10:56:12