Every new year, there are messages about “Remember to update your Copyright dates”. There are several JS and PHP snippets flying around that can help you do this. I had an idea today to make this as simple as possible for you. I shipped two updates today to make your lives easier.
- Foundation v6.10.6 adds new date helper utility classes
- Tardis v1.6.0 has a new Tardis Helper stack. This will be good for non-F6 users/themes.
With these new versions, you can simply place this wherever your copyright goes…
Copyright <span class="current-year">2021</span> My Company
Wherever you place the current-year
class, the contents of that will be replaced with the current year on page load. In the example above, I supplied a default of 2021. That will get replaced with the current year (now 2022) on page load.
But wait, there is more…
I figured while I was doing this, why stop at just the year. You have access to the following utility classes. Just like the example above, the current time data will populate where you place the class.
current-year
current-month
current-day
current-hour
current-minute
current-second
current-weekday
current-timeZoneName
current-dayPeriod
current-date
current-time
current-dateTime
The last 3 classes will actually output an actual full date time string. What is even better is that all output is 100% localized for the website’s language.
You have some flexibility with the formatting. The Tardis stack has options in the stack. With the Foundation 6 utility classes, there is a small JS snippet that is documented in the Utilities class section on the F6 Demo site.
If you don’t have Foundation 6 or Tardis, check them out…