Software, your way.
burger menu icon
WillMaster

WillMaster > LibraryWeb Content Preparation

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

The HTML 'time' Tag

Making Machine-Readable Dates and Times Available to Browsers

The HTML time tag is used to provide a machine-readable date and/or time for browsers and spiders.

When configured to do so, the browser can use the date and time information to interact with other applications — importing the date/time information into a calendar application, for example, or into reminder software. It also may allow better search results when searches require specific dates or times.

The time tag can have CSS styling like the span and other HTML tags can. The reason to use the time tag instead of the span tag is to provide machine-readable date and/or time for browsers and spiders.

Here is a template of how the time tag is coded:

<time datetime="[machine-readable]">[human-readable]</time>

Here is an example. The source code is further below, following a comment about the example.

Let's go !

In the above statement, "trick or treating at 5:30" is the human-readable part. The machine-readable part, in the time tag's datetime attribute, is 2025-10-31T17:30:00.000

Here is the source code for the above example:

Let's go <time datetime="2025-10-31T17:30:00.000" style="font-weight:bold;">trick or treating at 5:30</time>!

There are various ways to properly format the machine-readable value. The value may be a date only, a time only, and both date and time.

Date-only datetime Value Formats —

Valid date values are of these formats:

year
year-month
year-month-day
month-day

The year is always 4 digits (year 1 would be 0001). Month and day each are always 2 digits. Here are examples for each of the above formats.

datetime="2024"
datetime="2024-11"
datetime="2024-11-23"
datetime="11-23"

Time-only datetime Value Formats —

Valid time values are of these formats:

hour:minute
hour:minute:second
hour:minute:second.millisecond

The hour, minute, and second are always 2 digits. The millisecond is always 3 digits. Notice that the second/millisecond separator is a period character but hour/minute and minute/second separaters are a colon character. Here are examples.

datetime="00:19"
datetime="00:19:37"
datetime="00:19:37.237"

Date and Time datetime Value Formats —

There are two formats for date and time values:

year-month-day hour:minute:second.millisecond
year-month-dayThour:minute:second.millisecond

The difference between the two is that a space or a capital letter "T" may separate the date and time. Both versions are read the same way by browsers and spiders.

The year is 4 digits. The month, day, hour, minute, and second are 2 digits. The millisecond is 3 digits.

Here is an example of each.

datetime="2024-11-23 00:19:37.237"
datetime="2024-11-23T00:19:37.237"

The above is local time because no time zone is specified.

Specifying global time instead of local time:

To specify global time, a time zone offset is appended to the datetime value. There are five different ways the time zone offset can be specified.

year-month-day hour:minute:second.millisecondZ
year-month-day hour:minute:second.millisecond-hours:minutes
year-month-day hour:minute:second.millisecond-hoursminutes
year-month-day hour:minute:second.millisecond+hours:minutes
year-month-day hour:minute:second.millisecond+hoursminutes

The first format, with the letter "Z" appended specifies UTC (like GMT).

The second format specifies a minus offset of a certain number of hours and a certain number of minutes, with a colon character separating hours and minutes.

The third format is similar to the second format except there is no separating character for hours and minutes.

The fourth and fifth formats are similar to the second and third formats except a plus offset is specified instead of a minus offset.

The hours and minutes are both 2 digits.

As with the local time formats, the capital letter "T" may be used instead of a space to separate date and time.

Here is an example of each of the five formats with a space separating the date and time, then another five formats with the capital letter "T" instead of space for the date/time separation — 10 examples altogether.

datetime="2024-11-23 00:19:37.237Z"
datetime="2024-11-23 00:19:37.237-05:00"
datetime="2024-11-23 00:19:37.237-0500"
datetime="2024-11-23 00:19:37.237+02:00"
datetime="2024-11-23 00:19:37.237+0200"
datetime="2024-11-23T00:19:37.237Z"
datetime="2024-11-23T00:19:37.237-05:00"
datetime="2024-11-23T00:19:37.237-0500"
datetime="2024-11-23T00:19:37.237+02:00"
datetime="2024-11-23T00:19:37.237+0200"

With the datetime attribute and the time tag, you can give browsers and spiders an exact date or time or both in a format readable by them. Concurrently, you can also publish a time statement for humans to read.

(This article first appeared with an issue of the Possibilities newsletter.)

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC