In @contentful/f36-datetime
, there are two components (DateTime
and RelativeDateTime
) that will return a date.
RelativeDateTime
Provides a relative date string for resolutions ranging from seconds up through years. Should be used when absolute date and time is unnecessarily specific.
Examples
If we consider today as of August 18th of 2021 and we pass the following values to the <RelativeDateTime />
component
The component will display a day ago
baseDate
Passing a Normally, the component compares your date
with today’s date. If you want to compare it to some specific date
you need to provide baseDate
prop.
The component will display in a day
isRelativeToCurrentWeek
Using You can set isRelativeToCurrentWeek to true if you want to indicate that the date is relative only within a week. And if the difference is more than one week, just show the date without relativeness. It will compare the date to today or baseDate if provided.