开发者

Another HTML5 time element question

开发者 https://www.devze.com 2023-02-12 09:16 出处:网络
What does the following text mean below in layman\'s terms. If you can give me another example of machine-readable?

What does the following text mean below in layman's terms. If you can give me another example of machine-readable?

This element is intended as a way to encode modern dates and times in a machine-readable way so开发者_运维技巧 that, for example, user agents can offer to add birthday reminders or scheduled events to the user's calendar


Let's look at an example without the time element.

<html>
<head><title>Date of Birth</title></head>
<body>
Joe was born on 20 Jan 1985.
</body>
</html>

If you were writing a program to parse this HTML page, it would not be very easy to extract the date of birth. How will your program (i.e. a machine) know that "20 Jan 1985" is a date of birth? Humans do, because of the context surrounding the date.

Now consider this:

<html>
<head><title>Date of Birth</title></head>
<body>
Joe was born on <time datetime="1985-01-20">20 Jan 1985</time>.
</body>
</html>

Your program can now extract the date of birth quite easily simply by getting the time element's datetime attribute. The time element makes it easier to identify dates and times. For example, a browser (i.e. a machine) could detect this date and offer to add it to your calendar.

0

精彩评论

暂无评论...
验证码 换一张
取 消