从Firestore时间戳记显示日期(不是时间) [英] Display Date (not time) from Firestore Timestamp
本文介绍了从Firestore时间戳记显示日期(不是时间)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要从Firestore数据库提取时间戳,我只想向用户显示日期.原始时间戳为
I'm pulling a timestamp from a Firestore database, and I only want to display the date to the user. The original timestamp is
Timestamp(seconds=1555477200, nanoseconds=0)
我尝试了一些变体来获取日期,但是它们都具有相同的输出-
I've tried a few variations to get the Date, but they all have the same output-
到期日:2019年4月17日星期三06:10:21 GMT-0500(中部夏令时)
Due: Wed Apr 17 2019 06:10:21 GMT-0500 (Central Daylight Time)
<p>Due: ${Date(dueDate)}<br>
<p>Due: <time>${Date(dueDate)}</time><br>
<p>Due: <time type="date">${Date(dueDate)}</time><br>
如何切断时间戳的时间部分? (理想情况下,我想要"2019年4月17日",但如果当天也可以)
How do I cut off the time part of the timestamp? (Ideally, I'd want "April 17, 2019", but if the day is in there that's fine too)
推荐答案
您可以
var time= timeStampFromFirestore.toDate();
console.log(time);
console.log(time.toDateString());
请参阅完整的文档:
这篇关于从Firestore时间戳记显示日期(不是时间)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文