从Firestore中获取日期时,我得到了时间戳“秒:1608490949,纳秒:275000000”。我想将其打印为格式正确的日期和时间。因为是“ 2020年12月28日UTC + 5:30 AM 3:52:04”。下面是我的代码图片
obj.modify=this.dateconversion(obj.modify);
dateconversion( time:Timestamp){
return time.toDate();
}
It is returning me values "2020-12-27T22:22:04.000Z" but actual in firestore "December 28,2020 at
3:52:04 AM UTC+5:30".
Its seems giving me 5 hours back that's why one day back data is printing.
Can any one please suggest other way to do or where I am doing mistake.
您可以在此处调用javascript日期函数,因为这会转换为javascript日期
dateconversion( time:Timestamp){
return time.toDate().toString();
}
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Date/toString
或者,要进一步控制格式,可以使用momentjs [https://momentjs.com/docs/]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句