Expiration Date of cookie



Write a javascript code to set the expiration date of cookie.


<html>            
  <head>
    <script>
    
    function changedate()
    {
        var now = new Date();
        now.setMonth(now.getMonth() + 1);
        var Cookie_value = username.value;
        document.cookie = "username=" + Cookie_value +";expires="+ now.toUTCString();
        alert("Expiry Date of Cookie changed:" + "username=" + Cookie_value);
    }

    </script>
  </head>
<body>
    
    Enter cookie name:<input type="text" id="username"/>
    <input type="button" value="Extend Expiry Date" onclick="changedate()"/>

  </body>
</html>

Output: