[英]how can i take time.ctime away from time.ctime
Distance=200
import time
Time_started=time.ctime()
question=(input("has car gone pass sensor 1 \n:"))
if question=="yes":
print ("the time is",Time_started,"seconds")
Time_ended=time.ctime()
question2=(input("has car gone pass sensor 2 \n:"))
if question2=="yes":
print ("the time is",Time_ended,"seconds")
print ("")
Time_taken= (time.ctime() - Time_started)
print ("it took %f1 seconds" % Time_taken , "to travel 200m" )
i want to know if it is possible to take time.ctime away from each other to get the seconds by themselves 我想知道是否有可能将time.ctime彼此分开以自己获得秒数
为什么不使用time.time()代替time.ctime()?
You can use: time.time()
and time.ctime(secs)
您可以使用: time.time()
和time.ctime(secs)
Time_started=time.time()
If you want to convert that to something user friendly, you can do: 如果要将其转换为用户友好的内容,可以执行以下操作:
print ("the time is",time.ctime(Time_started))
You said you only wanted time.ctime because it is user friendly, so you can do this: 您说您只想要time.ctime,因为它对用户友好,因此您可以执行以下操作:
Use time.time()
to initialize Time_started
and Time_ended
, and use them whenever you need to calculate something (eg, the difference between them). 使用time.time()
初始化Time_started
和Time_ended
,并在需要计算某些内容(例如它们之间的差异)时使用它们。 But when you want to print the time to the user, use time.ctime(Time_started)
or time.ctime(Time_ended)
. 但是,当您要将时间打印给用户时,请使用time.ctime(Time_started)
或time.ctime(Time_ended)
。 time.ctime will then return a pretty string that describes the time you supplied it with. 然后time.ctime将返回一个漂亮的字符串,描述您提供时间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.