显示了一篇文章是多久以前用JavaScript写的

显示了一篇文章是多久以前用JavaScript写的,javascript,html,time,frontend,dayjs,Javascript,Html,Time,Frontend,Dayjs,我想显示一篇文章发布时的网站视图,即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>

我想显示一篇文章发布时的网站视图,即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>


唐纳德·特朗普总统对冠状病毒检测呈阳性。

10分钟前的照片

美国总统唐纳德·特朗普和第一夫人梅拉尼娅·特朗普 早些时候,他在推特上说,新冠肺炎检测呈阳性 星期五。

“我们将开始检疫和恢复过程 “马上,”他在等待测试结果时说 在成为一名高级助手后,他花了大量时间研究这个问题 一周内检测出新冠病毒-19呈阳性。

特朗普在确认了这一希望后发表了上述评论 希克斯是他最亲密的助手之一,他的诊断呈阳性 病毒星期四开始传播。希克斯开始感觉到轻微的症状 在从明尼苏达州的一次集会回家的飞机上 据一位政府官员说,星期三晚上 一位不愿透露姓名的官员向 披露私人信息。她被隔离了 从飞机上的其他人那里,她的诊断是正确的 该人士说,周四证实。

您可以试试

dayjs("DATE_TIME_STRING").fromNow()

例如:
dayjs(“2020-10-14 03:03:03:03”)。从现在开始()
,这将为您提供一天前的输出

是否有机会展示您迄今为止的尝试这是你的问题,你接受了答案