Page date from CSS Selector
Updating out-of-date content and ensuring that content is being reviewed on a regular basis is an important element of website maintenance.
As a web editor, you might want to focus on newly created pages, and an administrator might want to monitor pages that have been modified during the last week.
The "Page date from CSS Selector" policy rule can use certain date formats in the HTML code, enabling you to set up policies relating to the scenarios above.
Identifying dates on pages
Identifying the HTML element that contains the date is done using a CSS selector. The following example shows two <meta> tags in the <head> section of a page, and the first one shows when the page was last modified:
<head> <title>My page</title> <meta name="Last-Modified" content="2020-09-24T19:12:22Z" /> <meta name="Description" content="A description of the page's content" /> </head>
The CSS selector to match this "Last-Modified" meta tag would be meta[name='Last-Modified']. The policy will check if this element has any attribute with a valid date format and use that as the date. (In this case, it's the "content" attribute.)
Supported date formats
Three date formats are supported:
- Variants of ISO 8601
- RFCs 1123, 5322, 2822
- Unix Epoch
|Supports three granularities: Date, date with time, and date with time and fractions.|
The timezone identifier is Z for UTC, or can be provided as +01:00 or +0100.
No timezone identifier is interpreted as UTC.
Time, if provided, must be in 24-hour format.
|RFCs||ddd, dd, MMM yyyy HH:mm:ss GMT|
Thu, 24 Sep 2020 19:12:22 GMT
|Variants are commonly used for HTTP date headers, such as the Last-Modified header.|
Day and month names must be in English, as per the RFCs.
No timezone identifier is interpreted as UTC. Time must be in 24-hour format.
|ddd, dd, MMM yyyy HH:mm:ss K||Thu, 24 Sep 2020 19:12:22 +0100|
Thu, 24 Sep 2020 19:12:22 +01:00
Thu, 24 Sep 2020 19:12:22
|Unix Epoch||A large whole number||1600967542||The number of seconds since 1st of January 1970 (also known as the Unix Epoch).|
The date will be interpreted as UTC.
The following table shows how to construct valid dates using the built-in date functions in a range of programming languages:
|.NET||O, o, R, r||Standard Date and Time Format Strings|
|PHP||c, r||Date/Time Functions|
|Java||N/A||Java doesn't natively support ISO 8601, but the Joda-Time library does.|
Learn more about Custom Formatters.
What is ISO 8601?
ISO 8601 is an international standard for writing dates and times. Due to different date formats in different countries, it is very easy to misinterpret dates, e.g. confusing the numbers for days and months.
In 1988, the ISO (International Organization for Standardization) set a Global standard numeric date format, which was recognized internationally as the agreed way to represent dates:
- 2020-03-11: 11th March 2020
- 2020-11-03: 3rd November 2020
Want to learn more about CSS selectors?
Interested to learn more about CSS selectors? Read our article CSS Selectors & Siteimprove Policy and try out the CSS Selector rule in your policies.
Did you find it helpful?Send feedback