Description
Using Zope DateTime class in Plone programming
Some Plone dates are stored as Zope DateTime objects. This is different from standard Python datetime (notice the letter casing). Zope DateTime predates Python datetime which was added in Python 2.4. Zope DateTime is old code, so do rites necessary for your religion before programming with it.
ノート
Using Python datetime is recommended if possible. Zope DateTime should be dealt in legacy systems only as Python datetime is much more documented and widely used.
Since two different datetime object types are used, you need to often convert between them.
Please see
DateTime to datetime:
from Products.ATContentTypes.utils import DT2dt
python_dt = DT2dt(zope_dt)
This will fail silenty and you get a wrong date:
dt = DateTime("02.07.2010") # Parses like US date 02/07/2010
Please see
Example:
# Lazy ass way to parse both formats
# 2010/31/12
# 31.12.2010
try:
if "." in rendDate:
# European
end = DateTime(rendDate, datefmt='international')
else:
# US
end = DateTime(rendDate)