Search code examples
pythonmaximo

How to add 1 second to the current date in automation script in Maximo


How can I add 1 second to the current date in Python. I'm able to fetch the current Date and second separately however I'm not sure how to add 1 second to it.

currentDate = MXServer.getMXServer().getDate()
 currentSecond = currentDate.getSeconds()
 newSecond = currentSecond - 1

Solution

  • You have to use a Calendar. For example..

    from java.util import GregorianCalendar
    from psdi.server import MXServer
    
    currentDate = MXServer.getMXServer().getDate()
    cal = GregorianCalendar()
    cal.setTime(currentDate)
    cal.add(cal.SECOND, 1)
    print "currentDate: %s\nplusSecond: %s" % (currentDate.toString(), cal.getTime().toString())