# blockenberg/2.0.7/blocks/dynamic-date/frontend.js

Blockenberg — 600+ Advanced Gutenberg Blocks &amp; AI Agent for WordPress Block Editor, version 2.0.7. 44 lines.

- Page: https://pluginprobe.com/plugins/blockenberg/2.0.7/code/blocks/dynamic-date/frontend.js
- Raw: https://pluginprobe.com/plugins/blockenberg/2.0.7/raw/blocks/dynamic-date/frontend.js
- Modified: 2026-03-06T12:32:40+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/blockenberg/2.0.7/code/blocks/dynamic-date/frontend.js#L10-L20`.

```javascript
( function () {
  var FORMAT_MAP = {
    'long-date':    { opts: { weekday:'long', year:'numeric', month:'long', day:'numeric' } },
    'short-date':   { opts: { year:'numeric', month:'short', day:'numeric' } },
    'numeric-date': { opts: { year:'numeric', month:'2-digit', day:'2-digit' } },
    'year-only':    null,
    'time-12':      { opts: { hour:'numeric', minute:'2-digit', hour12: true } },
    'time-24':      { opts: { hour:'2-digit', minute:'2-digit', hour12: false } },
    'datetime':     { opts: { year:'numeric', month:'short', day:'numeric', hour:'numeric', minute:'2-digit' } }
  };

  function formatDate( format, tz ) {
    var now = new Date();
    if ( format === 'year-only' ) return String( now.getFullYear() );
    var entry = FORMAT_MAP[ format ];
    if ( !entry ) return now.toLocaleDateString();
    try {
      var opts = Object.assign( {}, entry.opts );
      if ( tz && tz !== 'site' && tz !== 'utc' ) opts.timeZone = tz;
      if ( tz === 'utc' ) opts.timeZone = 'UTC';
      return now.toLocaleString( navigator.language || 'en', opts );
    } catch (e) {
      return now.toLocaleString();
    }
  }

  document.querySelectorAll( '.bkdd-wrap' ).forEach( function ( wrap ) {
    var format = wrap.dataset.format || 'long-date';
    var tz     = wrap.dataset.tz || 'site';
    var live   = wrap.dataset.live === '1';
    var dateEl = wrap.querySelector( '.bkdd-date' );
    if ( !dateEl ) return;

    function update() {
      dateEl.textContent = formatDate( format, tz );
    }
    update();

    if ( live ) {
      setInterval( update, 1000 );
    }
  } );
} )();

```
