問題:編寫一個函數,要求輸入年月日時分秒,輸出該年月日時分秒的下一秒。如輸入2004年12月31日23時59分59秒,則輸出2005年1月1日0時0分0秒。 (c/c++、Java、Javascript、C#、Python)python
一、python:c++
#!/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)
二、函數