Input Datetime max Attribute

Definition and Usage

max Attribute sets or returns the value of the max attribute of the date-time field.

HTML max attribute specifies the maximum value (date and time) for the date-time field.

Tip:Use the max attribute and min attribute to create a valid value range.

Tip:To set or return the value of the min attribute, use min attribute

See Also:

HTML Reference Manual:HTML <input> max 属性

Example

Example 1

Get the furthest date and time allowed by the date-time field:

var x = document.getElementById("myDatetime").max;

Try It Yourself

Example 2

Change the furthest date and time:

document.getElementById("myDatetime").max = "2012-01-01T11:57Z";

Try It Yourself

Syntax

Return max attribute:

datetimeObject.max

Set max attribute:

datetimeObject.max = YYYY-MM-DDThh:mm:ssTZD

Attribute Value

Value Description
YYYY-MM-DDThh:mm:ssTZD

The furthest date and/or time allowed by the specified date-time field.

Component Description:

  • YYYY - Year (e.g., 2023)
  • MM - Month (e.g., 02 represents February)
  • DD - Day of the month (e.g., 15)
  • T - If a time is specified, then the separator is required
  • hh - Hours (e.g., 22 represents 10 PM)
  • mm - Minutes (e.g., 55)
  • ss - Seconds (e.g., 06)
  • TZD - Time zone indicator (Z stands for Zulu, also known as Greenwich Mean Time)

Technical Details

Return Value: 字符串值,表示允许的最远日期和时间。

浏览器支持

表中的数字注明了首个完全支持该属性的浏览器版本。

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
支持 10.0 支持 支持 支持

注意:元素 <input type="datetime"> 在除 Safari 之外的任何主流浏览器中均不显示任何日期时间字段/日历。