A Google Tag Manager (GTM) client-side variable template that returns the current date and time with timezone support and flexible formatting options.
- 39 Timezone Options: Covers major cities and timezones worldwide
- 20 Output Formats: From ISO 8601 to human-readable formats
- Custom Format Patterns: Create your own date/time format
- Multi-Locale Support: 13 languages for localized output
- Lightweight: Pure sandboxed JavaScript (no external dependencies)
- In Google Tag Manager, go to Templates > Variable Templates
- Click Search Gallery
- Search for "Current Date/Time Variable"
- Click Add to workspace
- Download the
template.tplfile from this repository - In Google Tag Manager, go to Templates > Variable Templates
- Click New
- Click the three-dot menu (top right) > Import
- Select the downloaded
template.tplfile - Click Save
- Go to Variables > User-Defined Variables
- Click New
- Choose Current Date/Time Variable from the template list
- Configure the options:
- Timezone: Select the timezone for the output
- Output Format: Choose the desired format
- Locale: Select language for localized text (day/month names)
- Save your variable
Select from 39 timezone options:
| Region | Timezones |
|---|---|
| Local | Browser's local timezone |
| UTC | Coordinated Universal Time |
| Americas | New York, Chicago, Denver, Los Angeles, Anchorage, Honolulu, Phoenix, Toronto, Vancouver, Mexico City, Sao Paulo, Buenos Aires |
| Europe | London, Paris, Berlin, Amsterdam, Madrid, Rome, Zurich, Stockholm, Moscow, Istanbul |
| Asia | Dubai, Kolkata, Bangkok, Singapore, Hong Kong, Shanghai, Tokyo, Seoul |
| Oceania | Sydney, Melbourne, Perth, Auckland |
| Africa | Cairo, Johannesburg |
Choose from 20 built-in formats:
| Format | Example Output |
|---|---|
| ISO 8601 | 2024-01-15T14:30:00 |
| ISO 8601 with Timezone | 2024-01-15T14:30:00-05:00 |
| Date Only | 2024-01-15 |
| Time Only | 14:30:00 |
| Time 12-hour | 2:30:00 PM |
| Date and Time | 2024-01-15 14:30:00 |
| Date and Time 12-hour | 2024-01-15 2:30:00 PM |
| Readable | January 15, 2024 2:30 PM |
| Unix Timestamp (ms) | 1705329000000 |
| Unix Timestamp (sec) | 1705329000 |
| Day of Week | Monday |
| Day of Week Short | Mon |
| Month Name | January |
| Year | 2024 |
| Month | 01 |
| Day | 15 |
| Hour (24h) | 14 |
| Hour (12h) | 2 |
| Minute | 30 |
| Custom Format | User-defined pattern |
When using "Custom Format", you can create your own pattern using these tokens:
| Token | Description | Example |
|---|---|---|
YYYY |
4-digit year | 2024 |
MM |
2-digit month | 01 |
DD |
2-digit day | 15 |
HH |
2-digit hour (24h) | 14 |
hh |
2-digit hour (12h) | 02 |
mm |
2-digit minute | 30 |
ss |
2-digit second | 45 |
A |
AM/PM | PM |
dddd |
Full day name | Monday |
ddd |
Short day name | Mon |
MMMM |
Full month name | January |
MMM |
Short month name | Jan |
Custom Format Examples:
| Pattern | Output |
|---|---|
YYYY/MM/DD |
2024/01/15 |
DD-MM-YYYY |
15-01-2024 |
dddd, MMMM DD, YYYY |
Monday, January 15, 2024 |
hh:mm A |
02:30 PM |
YYYY-MM-DD HH:mm:ss |
2024-01-15 14:30:45 |
Available locales for localized text output:
- English (US) -
en-US - English (UK) -
en-GB - German -
de-DE - French -
fr-FR - Spanish -
es-ES - Italian -
it-IT - Portuguese (Brazil) -
pt-BR - Dutch -
nl-NL - Japanese -
ja-JP - Chinese (Simplified) -
zh-CN - Korean -
ko-KR - Russian -
ru-RU - Arabic -
ar-SA
Create a variable with the "hour" format to track which hours users are most active:
Timezone: Local
Output Format: Hour (24h)
Use in a Custom Dimension in Google Analytics 4.
Create a variable to segment users by time of day:
Timezone: America/New_York
Output Format: Hour (24h)
Then create a lookup table variable to categorize:
- 6-12: Morning
- 12-18: Afternoon
- 18-22: Evening
- 22-6: Night
Push ISO timestamps to your data layer:
Timezone: UTC
Output Format: ISO 8601 with Timezone
Use with Custom HTML tag to show formatted date:
Timezone: Local
Output Format: Readable
Locale: (match your site's language)
Timezone: Local
Output Format: Day of Week
Use in triggers or custom dimensions to compare behavior.
- Uses pure GTM sandboxed JavaScript APIs (
getTimestampMillis,makeNumber,makeString,Math) - Calculates date components using mathematical algorithms (proleptic Gregorian calendar)
- Fixed timezone offsets are used (standard time) - DST is not automatically handled
- The variable is evaluated each time it's referenced (not cached)
- Works in all browsers without requiring additional permissions
This template uses fixed UTC offsets for each timezone, representing standard time. During daylight saving time periods, the displayed time may be off by one hour for timezones that observe DST. For applications requiring precise DST handling, consider:
- Using UTC timezone (which doesn't observe DST)
- Manually adjusting the offset during DST periods
- Using the "Local" timezone option which respects the browser's settings
This template requires minimal permissions:
- Logging (debug only): For development and debugging purposes
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
If you encounter any issues or have feature requests, please open an issue on GitHub.