简体   繁体   English

如何在firebase中将unix-timestamp转换为格式化的日期字符串

[英]How to convert a unix-timestamp to formatted date string in firebase

How do I convert a timestamp such as 1333699439 to 2008-07-17T09:24:17? 如何将时间戳如1333699439转换为2008-07-17T09:24:17?

Currently in firebase, I'm using - timestamp: Firebase.ServerValue.TIMESTAMP. 目前在firebase中,我正在使用 - timestamp:Firebase.ServerValue.TIMESTAMP。

the server return the timestamp in seconds So you need to multiple by thousand to get the time stamp in milisec like 服务器以秒为单位返回时间戳所以你需要乘以千倍才能得到像milisec那样的时间戳

var myDate = new Date(timestamp*1000);
var formatedTime=myDate.toJSON();

this formatedTime is your required format formatedTime是您所需的格式

您可以使用javascript Date对象执行此操作。

var myDate = new Date(timestamp_in_millis*1000);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM