ホームページ  >  記事  >  ウェブフロントエンド  >  HTML 時間タグ

HTML 時間タグ

PHPz
PHPzオリジナル
2024-09-04 16:30:11983ブラウズ

ご存知のとおり、HTML は Web 開発分野で進化し続けており、世界中で人気のあるマークアップ言語です。 Web 開発者は HTML 要素を更新し、学習する必要があると言われています。この記事では、タイムタグと呼ばれるいくつかの重要なタグについて学びます。人間にとっては、さまざまな形式の日付/時刻を読み取るのは簡単ですが、機械の場合、その時刻までに解析するのは簡単ではありません。今回は、タグは特定の期間を定義し、特定の Web ページの日付と時刻を指定します。したがって、これらは非常に便利であり、人間が読めるタグを表します。この人間が読める形式は、インターネット プロトコルの貴重な形式です。 タグは HTML 5 ではサポートされていますが、HTML 4.01 バージョンではサポートされていません。

時間は次の方法で定義できます:

  • 期間
  • 24 時間制の正しい時刻
  • グレゴリオ暦の日付

時間の進行の利点により、Web ページはより構造化され、検索エンジンが HTML コードを簡単に読み取って Web ページ上のアイデアを分析できるようになり、イベントのスケジュール設定や時間関連のイベント機能の開発に役立ちます。たとえば、検索エンジンでは現在のイベントと関連付けられており、視覚的な時間イベントによって現在の Web ページを上位にランク付けするのに役立ちます。

構文:

<time> 2020-01-28 </time>

基本的な日付/時刻属性を使用すると、コンピューター向けの特定の形式で一意の時刻タグが得られます。

上記の構文から、

であると言われています。タグには、時刻、日付の両方、または両方を一緒に保持します。想定される形式は、最大期間から下位期間の年 – 月 – 日 hh: mm: ss タイム ゾーンで指定されます。 Date Time 属性がない場合は、この形式が使用されます。

属性

属性は HTML において重要な役割を果たします。この HTML 要素を使用すると、ユーザーは仕事のスケジュールの日付や誕生日のリマインダーをそれぞれのカレンダーに柔軟に追加できます。もう 1 つの利点は、検索エンジンがより良い検索結果を提供できることです。この time 要素は、グローバル属性とイベント属性をサポートします。それとは別に、重要な属性は日付時刻です。 「月曜日」のような値を表示するには、「金曜日」の日時属性を表します。

以下の表は、この要素に関連する属性とその説明を示しています。
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.
属性名 説明 日付時刻 機械可読な要素の入力時間を指定します。 発行 コンテンツの発行日を指定するブール値があります。 テーブル>

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:

HTML 時間タグ

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:

HTML 時間タグ

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: 

HTML 時間タグ

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:

HTML 時間タグ

Conclusion

Therefore, we learned how to work with the

以上がHTML 時間タグの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
前の記事:HTMLボタンタグ次の記事:HTMLボタンタグ