Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.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日期获取年份_Javascript_Reactjs - Fatal编程技术网

从Javascript日期获取年份

从Javascript日期获取年份,javascript,reactjs,Javascript,Reactjs,我的数据库中有一个时间戳,我需要从中获取年份。时间戳保存如下 Timestamp {seconds: 1574096026, nanoseconds: 716000000} 如何从上面的时间戳中获取年份我尝试了newdate(timestamp).getFullYear(),但没有从时间戳中获取年份。有没有办法解决这个问题?新日期(毫秒)将毫秒作为参数接收,因此您需要先将秒和纳秒转换为毫秒 const时间戳={ 秒:1574096026, 纳秒:716000000 } 常量毫秒=`${time

我的数据库中有一个时间戳,我需要从中获取年份。时间戳保存如下

Timestamp {seconds: 1574096026, nanoseconds: 716000000}
如何从上面的时间戳中获取年份我尝试了
newdate(timestamp).getFullYear()
,但没有从时间戳中获取年份。有没有办法解决这个问题?

新日期(毫秒)将毫秒作为参数接收,因此您需要先将秒和纳秒转换为毫秒

const时间戳={
秒:1574096026,
纳秒:716000000
}
常量毫秒=`${timestamp.seconds}${timestamp.nanoseconds/1000000}`;
常量日期=新日期(+毫秒);
console.log(date.getFullYear())
选中“新建日期(毫秒)”将毫秒作为参数接收,因此需要先将秒和纳秒转换为毫秒

const时间戳={
秒:1574096026,
纳秒:716000000
}
常量毫秒=`${timestamp.seconds}${timestamp.nanoseconds/1000000}`;
常量日期=新日期(+毫秒);
console.log(date.getFullYear())
检查
var日期=新日期(1574096026000+716000000/1000000);
log(date.getFullYear())
var日期=新日期(1574096026000+716000000/1000000);
log(date.getFullYear())因为javascript“时间戳”以毫秒为单位,所以您需要
秒*1000+纳秒/1000000

let timestamp={秒:1574096026,纳秒:716000000}
let year=新日期(timestamp.seconds*1e3+timestamp.nanoseconds/1E6)。getFullYear();
对数(年)因为javascript“时间戳”以毫秒为单位,所以您需要
秒*1000+纳秒/1000000

let timestamp={秒:1574096026,纳秒:716000000}
let year=新日期(timestamp.seconds*1e3+timestamp.nanoseconds/1E6)。getFullYear();

对数(年)
新日期(timestamp.seconds+timestamp.nanoseconds/1E9)。getFullyear()
@jaromandaX它给出的年份是1970,你认为有这个时间戳的年份是什么?对不起,忘记了用1000:p
新日期(timestamp.seconds+timestamp.nanoseconds/1E9)。getFullyear()
@jaromandaX它给出的年份是1970年,你认为有这个时间戳的年份是什么?对不起,忘了用1000:p乘以整批