如何在Maximo的自动化脚本中向当前日期添加1秒

2024-09-27 07:35:36 发布

您现在位置:Python中文网/ 问答频道 /正文

如何在Python中为当前日期添加1秒。我能够分别获取当前日期和秒数,但我不确定如何在其中添加1秒

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

Tags: 秒数currentdatenewsecondgetdategetmxservergetsecondscurrentsecondmxserver
1条回答
网友
1楼 · 发布于 2024-09-27 07:35:36

你必须使用日历。例如

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())

相关问题 更多 >

    热门问题