I’d like to set a cookie with expire time in few hours in the future
There already exist a question which shows how to set a cookie:
How do you get and set cookies in Zope and Plone?
… but I didn’t find examples how to generate RFC 822 timestamp with Zope in “right way”. Looks like other frameworks do timestamp generation internally from datetime.
Also is it possible to have cookies which expiry on a browser closing? Is this one without expiry date?
You can see the answers to these two questions, in order to understand how to generate valid RFC 822 date time value.
In order to create a cookie which expires as soon as the browser is closed, just create a cookie without a expiry date. This will generate a session cookie, which will expire as soon as the browser session expires.