Skip to main content Sidebar Design tokens Components Layout Style utilities

We’d love to hear from you. Please reach out to us with any questions or inquiries you may have.

You can contact us via e‐mail at placer.coc.reports+contact@gmail.com.

We look forward to hearing from you!

Got it!
Skip to table of contents

The Placer Toolkit alpha has arrived! 🎉
Plenty of changes are coming your way—some big, some breaking, some even nuclear! Beware the changelog…

Bring it on!

    Format Date

    <pc-format-date> 1.0.0-alpha.1 experimental

    Formats a date/time using the specified locale and options.

    Localisation is handled by the browser’s Intl.DateTimeFormat API. No language packs are required.

    Edit

    The date attribute determines the date/time to use when formatting. It must be a string that Date.parse() can interpret or a Date object set via JavaScript. If omitted, the current date/time will be assumed.

    When using strings, avoid ambiguous dates such as 03/04/2024, which can be interpreted as 4 March 2024 or 3 April 2024 depending on the user’s browser and locale. Instead, always use a valid ISO 8601 date time string to ensure the date will be parsed properly by all clients.

    Demos#

    Date and time formatting#

    Formatting options are based on those found in the Intl.DateTimeFormat API. When formatting options are provided, the date/time will be formatted according to those values. When no formatting options are provided, a localised, numeric date will be displayed instead.

    Edit

    Hour formatting#

    By default, the browser will determine whether to use 12‐hour or 24‐hour time. To force one or the other, set the hour-format attribute to 12 or 24.

    Edit

    Localisation#

    Use the lang attribute to set the date/time formatting locale.

    Edit

    Properties#

    NameDescriptionReflectsDefault
    dateThe date/time to format. If not set, the current date and time will be used. When passing a string, it’s strongly recommended to use the ISO 8601 format to ensure timezones are handled correctly. To convert a date to this format in JavaScript, use date.toISOString().
    Type: Date | string
    new Date()
    weekdayThe format for displaying the weekday.
    Type: "narrow" | "short" | "long" | undefined
    eraThe format for displaying the era.
    Type: "narrow" | "short" | "long" | undefined
    yearThe format for displaying the year.
    Type: "numeric" | "2-digit" | undefined
    monthThe format for displaying the month.
    Type: "numeric" | "2-digit" | "narrow" | "short" | "long" | undefined
    dayThe format for displaying the day.
    Type: "numeric" | "2-digit" | undefined
    hourThe format for displaying the hour.
    Type: "numeric" | "2-digit" | undefined
    minuteThe format for displaying the minute.
    Type: "numeric" | "2-digit" | undefined
    secondThe format for displaying the second.
    Type: "numeric" | "2-digit" | undefined
    timeZoneName
    time-zone-name
    The format for displaying the time.
    Type: "short" | "long" | undefined
    timeZone
    time-zone
    The time zone to express the time in.
    Type: string | undefined
    hourFormat
    hour-format
    The format for displaying the hour.
    Type: "auto" | "12" | "24"
    "auto"
    updateComplete A read‐only promise that resolves when the component has finished updating.

    Learn more about attributes and properties.

    Importing#

    If you’re using the autoloader or the standard loader, you can skip this section. But if you’re cherry picking, you can use any of the following snippets to import this component.

    CDN (script tag) CDN (import) npm (import)

    To manually import this component from the CDN, copy this code snippet and paste it in your HTML.

    <script type="module" src="https://cdn.jsdelivr.net/npm/placer-toolkit@1.0.0-alpha.1/cdn/components/format-date/format-date.js"></script>

    To manually import this component from the CDN, copy this code snippet and paste it in your JavaScript file.

    import "https://cdn.jsdelivr.net/npm/placer-toolkit@1.0.0-alpha.1/cdn/components/format-date/format-date.js";

    To manually import this component from npm, copy this code snippet and paste it in your JavaScript file.

    import "placer-toolkit/dist/components/format-date/format-date.js";