私は最近、以下の部分で見られるように、Pythonプログラムの作業を開始しました。Pythonとtime/datetime
# General Variables
running = False
new = True
timeStart = 0.0
timeElapsed = 0.0
def endProg():
curses.nocbreak()
stdscr.keypad(False)
curses.echo()
curses.endwin()
quit()
# Draw
def draw():
stdscr.addstr(1, 1, ">", curses.color_pair(6))
stdscr.border()
if running:
stdscr.addstr(1, 3, t.strftime("%H:%M.%S", t.ctime(timeStart - timeElapsed)))
stdscr.redrawwin()
stdscr.refresh()
# Calculate
def calc():
if running:
timeElapsed = t.clock() - timeStart
stdscr.border()
stdscr.addstr(1, 3, t.strftime("%H:%M.%S", t.gmtime(t.clock() - t.clock())))
# Main Loop
while True:
# Get Input
kInput = stdscr.getch()
# Close the program
if kInput == ord('q'):
endProg()
# Stop the current run
elif kInput == ord('s'):
stdscr.addstr(1, 3, t.strftime("%H:%M.%S", t.gmtime(t.clock() - t.clock())))
running = False
new = True
# Start a run
elif kInput == ord(' ') and new:
running = not running
new = not new
timeStart = dt.datetime.now()
# Toggle the timer
elif kInput == ord('p') and not new:
timeStart = dt.datetime.now() - timeStart
running = not running
calc()
draw()
何かが右に見ていない場合は私のプログラムでは、ソリューション間のビット現在、申し訳ありませんです。私は説明することよりも喜んでいるでしょう。
Python用の時間と日時のモジュールについて、私は過去数時間をオンラインで読んでいました。目標を達成するためにどのように使うことができるのか理解しようとしましたが、実装しようとしましたが、 。
基本的には、ボタンが押されてからの経過時間を測定し、それを1時間:分秒の形式で表示できるようにするプログラムが必要です。減算は非常に困難になり、timedeltaのようなものを実装する必要がありました。私がオンラインで読んだことから、datetimeモジュールなしでは自分が望んでいることをする方法はありませんが、問題は何も与えません。
もっと簡単な解決法はありますか?私のコードには未解決のエラーがありますか?どのように愚かですか?
import time
star = time.time()
# run long processing...
elapsed = time.time() - start
のEtほら:'time.time`を使用して
'time.time'を使って経過時間を測定できます。 –