Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I specify a geographic location with the HTML "time" element?

Tags:

html

The HTML5 specs for the time element have a note under the heading "A valid time-zone offset string" that says this:

For times without dates (or times referring to events that recur on multiple dates), specifying the geographic location that controls the time is usually more useful than specifying a time zone offset, because geographic locations change time zone offsets with daylight savings time. [...]

While I totally agree with this statement, I have been wondering - and this is my question - how can I specify a geographic location in the time element? I've been looking through the specs but I haven't found a clue. Additional web research also didn't yield any useful information. Can someone point me in the right direction?

BTW: I'm a beginner in web programming, and although this really seems to be just a minor detail I like to get things right from the start.

like image 431
herzbube Avatar asked Sep 07 '25 15:09

herzbube


2 Answers

As far as I am aware, there is no way to specify <time> via region with raw HTML. I believe the documentation is simply stating that it's more useful to do it based on region, not that it is necessarily possible with raw HTML. This can certainly be achieved with a back-end language however, and injected into the <time> element (or datetime attribute).

Timezones can be specified with +, offset in relation to GMT:

<!-- GMT+1 (like Italy) -->
<time>+01:00</time>

And can be combined with fully-qualified times as well:

<!-- 16th September 2014 at 18 hours, 20 minutes, and 30 seconds
     in a time zone of GMT+1 (like Italy) -->
<time>2014-09-16T18:20:30+01:00</time> in Italy

As is demonstrated above, perhaps the best you can do is explicitly state the relevant region, such as <time …>…</time> in Italy.

In order to retrieve the geographic timezone, IANA has a list of all applicable timezones per region.

Dates should be in the format yyyy-mm-ddTHH:MM[:SS[.mmm]] or yyyy-mm-dd HH:MM[:SS[.mmm]], where:

  • H stands for hours
  • M stands for minutes
  • S stands for seconds
  • m stands for milliseconds
  • The square brackets indicate the parts that are optional

Hope this helps! :)

like image 68
Obsidian Age Avatar answered Sep 09 '25 22:09

Obsidian Age


From W3:

Definition and Usage

The tag defines a human-readable date/time.

This element can also be used to encode dates and times in a machine-readable way so that user agents can offer to add birthday reminders or scheduled events to the user's calendar, and search engines can produce smarter search results.

From Mozilla:

The HTML time element represents either a time on a 24-hour clock or a precise date in the Gregorian calendar (with optional time and timezone information).

So in other words, the time element isn't really supposed to be used for a precise geolocation, but maybe a timezone. For location, like @Ryan suggested, do something along the lines of <time …>…</time> in Paris

like image 28
Jerfov2 Avatar answered Sep 10 '25 00:09

Jerfov2