简体   繁体   English

显示多久前用 JavaScript 发布的帖子

[英]Showing how long ago a post was made in JavaScript

I would like to show website views when an article was posted ie, 1 hour ago, 4 ,mins ago, 2 years ago, etc. I would like to use DAY.JS to do the task.我想在发布文章时显示网站浏览量,即 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>

You can try你可以试试

dayjs("DATE_TIME_STRING").fromNow()

ex: dayjs("2020-10-14 03:03:03").fromNow() , this would give you the output as a day ago .例如: dayjs("2020-10-14 03:03:03").fromNow() ,这会给你a day ago的输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM