问题:编写一个函数,要求输入年月日时分秒,输出该年月日时分秒的下一秒。如输入2004年12月31日23时59分59秒,则输出2005年1月1日0时0分0秒。 (c/c++、Java、Javascript、C#、Python)

1、python:

#!/usr/bin/python3

import datetime

def addOneSecond(timeStr):
    d1 = datetime.datetime.strptime(timeStr, "%Y-%m-%d %H:%M:%S")

    d1 = d1 + datetime.timedelta(seconds=1)

    rtn = d1.strftime("%Y-%m-%d %H:%M:%S")
    return rtn


dtime = addOneSecond("2014-12-31 23:59:59")
print(dtime)

2、

 

相关文章:

  • 2021-12-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-26
  • 2021-10-05
  • 2021-11-28
  • 2021-10-14
猜你喜欢
  • 2021-12-26
  • 2022-12-23
  • 2021-05-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案