FormattedDate
Reference
- The
FormattedDatecomponent is designed to display a formatted date string. - It uses the
useSettingsContexthook to access global settings, such as the date format and UTC offset, and formats the provideddateStrusing theformatDateutility function.
Props:
dateStr: A string representing the date to be formatted.style: An optional inline style object to customize the appearance of the rendered<span>.
Components:
FormattedDate: Formats and displays the full date based on the globaldateFormatandutcOffset.FormattedDateWithOnlyMonthYear: Similar toFormattedDate, but formats the date to show only the month and year using thegetMonthYearDateFormatutility.
- Both components return a
<span>element containing the formatted date, styled using the optionalstyleprop.
Usage Example
function Example(pageContext) {
const { protrakComponents } = React.useContext(customWidgetContext);
const { FormattedDate } = protrakComponents;
return (
<div>
<H3>Date</H3>
<FormattedDate dateStr="2021-10-19T00:00:00.000Z" />
<div/>
);
};