从firestore获取日期时,我正在获取时间戳"秒:1608490949、纳秒:275000000";。我想把它打印成格式正确的日期和时间。事实上;2020年12月28日凌晨3:52:04 UTC+5:30";。下面是我的代码图片
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/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toString
或者,为了更好地控制格式,您可以使用momentjs[https://momentjs.com/docs/]