Machine-readable datetime string (ISO 8601 format, e.g., "2024-01-15" or "2024-01-15T14:30:00Z")
HTMLTimeElement with datetime attribute and display text, or null if required params are missing
// Simple date
const dateElement = createTimeElement({
datetime: '2024-01-15',
displayText: 'January 15, 2024'
});
// Date with time
const dateTimeElement = createTimeElement({
datetime: '2024-01-15T14:30:00Z',
displayText: 'Jan 15, 2024 at 2:30 PM'
});
// Relative time
const relativeElement = createTimeElement({
datetime: '2024-01-15',
displayText: '3 days ago'
});
Creates an HTML time element with formatted display text and machine-readable datetime
The time element provides semantic meaning to dates and times, improving accessibility and enabling browser features like calendar integration. The datetime attribute should use a valid datetime string (ISO 8601 format recommended).