Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the current year using css?

Tags:

date

css

I was appending copyright message to web page while printing, i have used following code

@media print
{
    .page:after
    {
        content: "© 2013 Copyright message";
        font-size: 14px;
        position: absolute;
    }
}

Is there any default way to get the current year using css?

like image 924
Pandiyan Cool Avatar asked Jan 03 '14 12:01

Pandiyan Cool


2 Answers

You can attach date to the div itself (data-date) and generate it on server side/javascript. Then in CSS you can grab it (attr(data-date)) and attach to content. It would look like this (sorry, untested)

content: "©  " attr(data-date) " Copyright message";

https://developer.mozilla.org/en-US/docs/Web/CSS/attr

http://davidwalsh.name/css-content-attr

like image 184
Michal Avatar answered Oct 09 '22 03:10

Michal


window.onload = function()
{
  document.getElementById("spanYear").innerHTML = new Date().getFullYear();
}
Copyright 1900-<span id="spanYear"></span>
like image 25
Jason L Avatar answered Oct 09 '22 03:10

Jason L