Custom Components
Current Date and Time
Live Preview

Current Date and Time

Instructions

Overview

Easily add a live date and time display to your website with customizable formatting and timezone adjustments.

Getting Started

Quick Start

  1. Click the Copy Component button on the top of the page.
  2. Paste the component into your Webstudio site.

Manual Start

  1. Add the Script: Copy and paste this code into your website's after the component:

[code-block]<script type="module" src="https://drevo.b-cdn.net/Library/Custom%20Components/Current%20Date%20Time/current-date-time-v1.0.js"></script>[/code-block]

  1. Add the Display Element: Place a Box element or a <div> where you want the date and time to appear, and add these custom attributes: <div dv-datetime-format="Y-M-D h:m:s" dv-datetime-timezone="0"></div>

current date and time attributes

Customization Options

Date & Time Format

  • Use these placeholders in the dv-datetime-format attribute:
    • Y = Year (e.g., 2023)
    • M = Month (e.g., 10)
    • D = Day (e.g., 05)
    • h = Hour (e.g., 14)
    • m = Minute (e.g., 30)
    • s = Second (e.g., 00)
  • Example: dv-datetime-format="D/M/Y h:m" → "05/10/2023 14:30"

Timezone Adjustment

  • Use the dv-datetime-timezone attribute to set the timezone offset from UTC.
  • Example: dv-datetime-timezone="2" → UTC+2
  • Valid range: -12 to 12

Notes

  • The time updates automatically every second.
  • If the timezone is invalid, it will show "Invalid timezone".
  • Only use the specified placeholders in the format string; other characters will appear as-is.