如何解决显示多长时间前用JavaScript发表的帖子
我想显示发布文章的网站浏览量,即1小时前,4分钟前,2年前,等等。 我想使用DAY.JS来完成任务。
<!--This is my html & bootstrap code-->
<div>
<h1 class="font-weight-600 mb-1">
President Donald Trump tests positive of coronavirus.
</h1>
<p class="fs-13 text-muted mb-0">
<span class="mr-2">Photo </span> 10 Minutes ago
</p>
<div class="rotate-img">
<img src="../assets/images/news/trump-tests-positive.jpeg"
alt="banner"
class="img-fluid mt-4 mb-4"/>
</div>
<p class="mb-4 fs-15">
US President Donald Trump and First Lady Melania Trump
tested positive for COVID-19,he said in a tweet early
on Friday.
</p>
<p>"We will begin our quarantine and recovery process
immediately," he said as they awaited the test results
after a top aide he spent substantial time with this
week tested positive for COVID-19.
</p>
<p>
Trump's comments came after he confirmed that Hope
Hicks,one his closest aides,had tested positive for
the virus Thursday. Hicks began feeling mild symptoms
during the plane ride home from a rally in Minnesota
Wednesday evening,according to an administration
official,who spoke on condition of anonymity to
disclose private information. She was quarantined away
from others on the plane and her diagnosis was
confirmed Thursday,the person said.
</p>
</div>
解决方法
您可以尝试
dayjs("DATE_TIME_STRING").fromNow()
例如:dayjs("2020-10-14 03:03:03").fromNow()
,这将使您的输出为a day ago
。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。