[Maya] Date/time attribute?

I would like to add a custom attribute to some of my nodes. It will hold some timestamp information. It does not have to be super accurate. Just a date, hour, and minutes. Does Maya have any built-in way to handle timestamp info?

If not, does anyone have advice for how do handle it? I am thinking of using a string attribute. Then my Python code can handle converting between string and datetime info.

A string attribute would be the most straightforward and would be human readable. Python has good support for string representations of date/time info.

Okay, that worked. Here is what I came up with (for a string attribute named “testDatetime”):

def getDatetime(self):
    date = None
    if cmds.listAttr(self.nodeName, string='testDatetime'):
        dateStr = cmds.getAttr(self.nodeName+'.testDatetime')
        if dateStr:
            try:
                date = datetime.datetime.strptime(dateStr, self.getDatetimeFormat())
            except ValueError as e:
                cmds.warning(e.message)
    return date

def setDatetime(self, datetimeValue):
    if cmds.listAttr(self.nodeName, string='testDatetime'):
        # Convert from a datetime object to a string
        try:
            dateStr = datetimeValue.strftime(self.getDatetimeFormat())
        except AttributeError as e:
            if not isinstance(datetimeValue, datetime.datetime):
                t = datetimeValue.__class__.__name__
                errMsg = ('Function "setDatetime" expects a datetime '
                          'object, but received a {0} instead').format(t)
                raise rer.RetroTypeError(errMsg)
            else:
                cmds.warning(e.message)
                return
        cmds.setAttr(self.nodeName+'.testDatetime', dateStr, type='string')

def getDatetimeFormat(self):
    return '%Y/%m/%d %H:%M %p'