HTML time tag - correct date format

橙三吉。 提交于 2019-12-21 21:19:17

问题


I am wanting to use the correct format and standards to put the time tag in my html document.

Is this the correct way to do it?

<time datetime="2014-03-26T12:48:42.733Z">26/03/2014</time>

Thanks


回答1:


The Format is YYYY-MM-DDThh:mm:ssTZD

The date or time being specified. Explanation of components:

YYYY - year (e.g. 2011)
MM - month (e.g. 01 for January)
DD - day of the month (e.g. 08)
T - a required separator if time is also specified
hh - hour (e.g. 22 for 10.00pm)
mm - minutes (e.g. 55)
ss - seconds (e.g. 03)
TZD - Time Zone Designator (Z denotes Zulu, also known as Greenwich Mean Time)

So Yes

Source




回答2:


As per the specs:

A valid date-time as defined in [RFC 3339], with these additional qualifications:

  • the literal letters T and Z in the date/time syntax must always be uppercase
  • the date-fullyear production is instead defined as four or more digits representing a number greater than 0

Examples:

1990-12-31T23:59:60Z

1996-12-19T16:39:57-08:00




回答3:


Yes, see RFC 3339 and input type=datetime




回答4:


The time element as defined in HTML5 must specify time, date, time and date, or other applicable designation in a specific machine-readable format, as described in the draft. This designation may appear as the element content, e.g.

<time>2014-03-26></time>

If it does not (typically, when the content specifies a date or time in human-readable form in some language), the machine-readable designation must appear as the value of the datetime attribute, e.g.

<time datetime="2014-03-26">26/03/2014</time>

The notation in the question is not adequate, as the value of the attribute must be “a representation of the element's contents in a machine-readable format”, and a date and time denotation, down to milliseconds, can hardly be said to represent a date.

Note: There is no evidence of browsers or search engines making any use of time markup, so such markup is only potentially useful.




回答5:


The spec here lays down the format. There's no mention of fractional time, so no - this is not correct.

However, this will be correct:

<time datetime="2014-03-26T12:48:42Z">26/03/2014</time>


来源:https://stackoverflow.com/questions/23214732/html-time-tag-correct-date-format

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!