react - DayJs, plugin for time format

0 votes
47 views
added Mar 10, 2022 in React by lcjr First Warrant Officer (9,190 points)
import dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';

const created = "<timestamp goes here>";

// Use
{dayjs(created * 1000).fromNow()} 2 days ago
{dayjs(created * 1000).format('DD MMM YYYY')} 01 Feb 2022

// Dayjs Docs
https://day.js.org/docs/en/display/format

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...