Class Time<T extends Time<T>>


public class Time<T extends Time<T>> extends PhrasingContentElement<T>
Represents an HTML <time> element for marking up dates and times in a machine-readable format.

This class provides functionality to create semantic time elements that can display human-readable dates and times while also providing machine-readable datetime values. The time element helps browsers, search engines, and assistive technologies understand temporal information, enabling features like calendar integration, reminders, and improved search indexing. It can represent various temporal concepts including specific dates, times, durations, and datetime combinations.

Features:

  • Marks up dates and times semantically
  • Provides machine-readable datetime attribute
  • Supports human-readable display text
  • Enables calendar integration and event scheduling
  • Improves search engine understanding of temporal content
  • Assists screen readers in announcing dates and times correctly
  • Extends
    invalid reference
    TextElement
    for text content management

Usage:


 // Create time element with human and machine-readable formats
 Time eventTime = new Time("January 1, 2024");
 eventTime.setDateTime("2024-01-01");

 // Time with specific hour
 Time meetingTime = new Time("2:30 PM");
 meetingTime.setDateTime("14:30");

 // Full datetime with timezone
 Time fullDateTime = new Time("New Year's Eve 2024, 11:59 PM EST");
 fullDateTime.setDateTime("2024-12-31T23:59:00-05:00");

 // Duration
 Time duration = new Time("2 hours");
 duration.setDateTime("PT2H");

 // Year only
 Time year = new Time("Published in 2024");
 year.setDateTime("2024");
 
Since:
2016
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • Time

      public Time()
      Constructs an empty Time element.

      Creates a new <time> element with no initial text content. The datetime attribute and display text can be set later using setDateTime(String) and text manipulation methods.

    • Time

      public Time(String text)
      Constructs a Time element with the specified display text.

      Creates a new <time> element containing the provided human-readable text. For proper semantic markup, also call setDateTime(String) to provide the machine-readable datetime value.

      Parameters:
      text - the human-readable text to display for the time/date
  • Method Details

    • setDateTime

      public final T setDateTime(String datetime)
      Sets the machine-readable datetime value for this time element.

      Specifies the datetime in a standard format that machines can parse. Common formats include:

      • Date: "2024-01-01"
      • Time: "14:30" or "14:30:00"
      • DateTime: "2024-01-01T14:30:00"
      • DateTime with timezone: "2024-01-01T14:30:00-05:00"
      • Duration: "PT2H30M" (2 hours, 30 minutes)
      • Year/Month: "2024" or "2024-01"
      Parameters:
      datetime - the machine-readable datetime value in ISO 8601 format