ご存知のとおり、HTML は Web 開発分野で進(jìn)化し続けており、世界中で人気のあるマークアップ言語です。 Web 開発者は HTML 要素を更新し、學(xué)習(xí)する必要があると言われています。この記事では、タイムタグと呼ばれるいくつかの重要なタグについて學(xué)びます。人間にとっては、さまざまな形式の日付/時(shí)刻を読み取るのは簡(jiǎn)単ですが、機(jī)械の場(chǎng)合、その時(shí)刻までに解析するのは簡(jiǎn)単ではありません。今回は、タグは特定の期間を定義し、特定の Web ページの日付と時(shí)刻を指定します。したがって、これらは非常に便利であり、人間が読めるタグを表します。この人間が読める形式は、インターネット プロトコルの貴重な形式です。 タグは HTML 5 ではサポートされていますが、HTML 4.01 バージョンではサポートされていません。
時(shí)間は次の方法で定義できます:
- 期間
- 24 時(shí)間制の正しい時(shí)刻
- グレゴリオ暦の日付
時(shí)間の進(jìn)行の利點(diǎn)により、Web ページはより構(gòu)造化され、検索エンジンが HTML コードを簡(jiǎn)単に読み取って Web ページ上のアイデアを分析できるようになり、イベントのスケジュール設(shè)定や時(shí)間関連のイベント機(jī)能の開発に役立ちます。たとえば、検索エンジンでは現(xiàn)在のイベントと関連付けられており、視覚的な時(shí)間イベントによって現(xiàn)在の Web ページを上位にランク付けするのに役立ちます。
構(gòu)文:
<time> 2020-01-28 </time>
基本的な日付/時(shí)刻屬性を使用すると、コンピューター向けの特定の形式で一意の時(shí)刻タグが得られます。
上記の構(gòu)文から、
であると言われています。タグには、時(shí)刻、日付の両方、または両方を一緒に保持します。想定される形式は、最大期間から下位期間の年 – 月 – 日 hh: mm: ss タイム ゾーンで指定されます。 Date Time 屬性がない場(chǎng)合は、この形式が使用されます。
屬性
屬性は HTML において重要な役割を果たします。この HTML 要素を使用すると、ユーザーは仕事のスケジュールの日付や誕生日のリマインダーをそれぞれのカレンダーに柔軟に追加できます。もう 1 つの利點(diǎn)は、検索エンジンがより良い検索結(jié)果を提供できることです。この time 要素は、グローバル屬性とイベント屬性をサポートします。それとは別に、重要な屬性は日付時(shí)刻です。 「月曜日」のような値を表示するには、「金曜日」の日時(shí)屬性を表します。
以下の表は、この要素に関連する屬性とその説明を示しています。
Attribute Name |
Description |
DateTime |
It specifies a machine-readable input time of the element. |
Pubdate |
It has a Boolean value that Specifies the publication date of the content. |
屬性名 |
説明 |
日付時(shí)刻 |
機(jī)械可読な要素の入力時(shí)間を指定します。 |
発行 |
コンテンツの発行日を指定するブール値があります。 |
テーブル>
There are some different ways of representing the date-time attribute. The profile of ISO 8601 provides the standards which follow the ABNF notation. And the letters below ‘T’ and ‘Z’ should be declared in the Upper case.
1. Year and Month
Very Simple Format with the year before.
2019 – 08
2. Date Alone
1946-08-17
3. Date without Year
08-21
4. Only Time Display
13: 55: 30. 522
5. Date and Time
2014 – 08 -21T15:55
Here T is for separation between Date and Time.
6. Time Zone Format
It initiates with either plus or minus and, in some cases, ( : ) is replaced With the capital ‘Z’.
+ 08 : 05
7. Year and Week
Follow the corresponding number of weeks after the letter ‘W’ to represent a week.
2017 – W 20
8. Duration (with Two methods)
2w 3d 4 h 25 min 12.402s
Also, it supports global attribute along with this element like id, class, style and supporting event attributes like onabort, onfocus, onclick, onmousedown, onmouseout, onkeyup, onchange, ondrag, ondrop, onselect, onmessage, onscroll.
Examples to Implement HTML Time Tag
Using this tag, You can display the date or time without a datetime attribute. The following are some examples:
Example #1 – using a
Code:
<!DOCTYPE html>
<html>
<head>
<title>
HTML Time Tag
</title>
</head>
<body style="text-align:left;">
<h2>HTML Time Tag demo</h2>
<p> India celebrate as
<time>2020-01-26</time> Republic day
</p>
</body>
</html>
Output:

Example #2
Making a time element to the title attribute to show detailed information about the user in a nice human-readable or machine-readable format.
Code:
<!DOCTYPE html>
<html>
<body>
<h2> <center> Date Time Example </center> </h2>
<h3>The Stand- Up Comedy show starts at <time datetime="2018-07-04T20:00:00Z">20:00</time> coming Saturday.</h3>
<h3>The preview show starts in <time datetime="PT3H0M3S">5h 1m 0s</time>.</h3>
</body>
</html>
In the below Output, the time tag instructs the browser about the text used between the attribute is a time reference ( 5 h 1m 0s) but doesn’t display the time attribute.
Output:

Example #3 – Using Css.
Code:
<!doctype html>
<html>
<body>
<article>
<body style="background-color:yellow;">
<h1>Title of the document</h1>
<p>Introduction to the Article</p>
</article>
<footer>
<p>This content is published on <time>2016-1-20</time>.</p>
<p>Our shop opens at <time>08:00</time>.</p>
</footer>
</body>
</html>
Output:?

Example #4 – Using pubdate attribute.
Code:
<!DOCTYPE html>
<html>
<body>
<article>
<h1>A good Article</h1>
<p>Introduction on a given Article.</p>
<footer>
<p>Content published on <time datetime="2019-02-04" pubdate>February the 4th, 2019</time>
</footer>
</article>
</body>
</html>
Output:

Conclusion
Therefore, we learned how to work with the
以上がHTML 時(shí)間タグの詳細(xì)內(nèi)容です。詳細(xì)については、PHP 中國(guó)語 Web サイトの他の関連記事を參照してください。