如何使用从服务器接收到的秒数显示用户的“最后一次看到”时间
how to show user's “last seen at” time using the seconds received from the server
我想显示用户最后一次在线的时间,比如 whatsapp
使用 xmpp 和 angular
我发出了一个 xmpp 请求,我得到了最后一次看到的用户,我想将其转换为时间
我得到了什么:
用户最后一次出现是在 903 秒前
我想要什么:
用户最后一次出现是在 11:30 下午
服务器上次 Activity 响应¶
<iq from='juliet@capulet.com'
id='last1'
to='romeo@montague.net/orchard'
type='result'>
<query xmlns='jabber:iq:last' seconds='903'>Heading Home</query>
</iq>
如果你将从服务器接收到的秒值赋给一个变量,你可以像下面那样做。
const timeInSeconds = getValueFromServer();
const lastLoggedInTime = new Date(Date.now() - timeInSeconds * 1000);
在您的 html 模板中,您可以使用 lastLoggedInTime
变量来显示日期。
我想显示用户最后一次在线的时间,比如 whatsapp 使用 xmpp 和 angular
我发出了一个 xmpp 请求,我得到了最后一次看到的用户,我想将其转换为时间
我得到了什么:
用户最后一次出现是在 903 秒前
我想要什么:
用户最后一次出现是在 11:30 下午
服务器上次 Activity 响应¶
<iq from='juliet@capulet.com'
id='last1'
to='romeo@montague.net/orchard'
type='result'>
<query xmlns='jabber:iq:last' seconds='903'>Heading Home</query>
</iq>
如果你将从服务器接收到的秒值赋给一个变量,你可以像下面那样做。
const timeInSeconds = getValueFromServer();
const lastLoggedInTime = new Date(Date.now() - timeInSeconds * 1000);
在您的 html 模板中,您可以使用 lastLoggedInTime
变量来显示日期。