- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我在树莓派终端遇到了一个问题。
>>> alarm = input('Please input the time for the alarm in format HHMM: \n ')
>>> print(alarm)
我输入 0700,按回车键,但它打印出 448 而不是 0700。当我在 IDLE 中尝试它时,它输出 0700。为什么它不会在 raspberry pi 终端中输出 0700?我怎样才能让终端发出 0700?
最佳答案
input() 函数会将您的输入转换为字符串。
0070 被认为是一个八进制数。它先转换为十进制数,然后再转换为字符串。
print str(0070)
>>> 56
import time
alarm = str(raw_input('Please input the time for the alarm in format HHMM: \n '))
print alarm
>>> Input: 0080
>>> Output: 0080
您应该验证用户输入的时间。例如,您不应允许用户输入类似 4012 的时间。您可以使用 datetime 模块验证时间,如下所示:
import datetime
try:
a = datetime.datetime.strptime(raw_input('specify time in HHMM format: '), "%H%M")
print a.strftime("%H%M")
except:
print "Please enter correct time in HHMM format"
使用日期时间对象还有其他优点。您可以根据自己的时间执行各种操作。例如。向其中添加时间,从中减去时间,将其转换为各种格式等。阅读此内容以获取更多信息:https://docs.python.org/2/library/datetime.html
关于python - 将时间作为 HHMM 格式的用户输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40796769/
所以我有一系列的时间: ArrayList times = new ArrayList(); times.add("1240"); times.add("1028"); times.add("0923
我想将时间用作 HHMM 格式,例如下午 4 点在军队中的 1600 小时。我很好奇:有没有办法通过一些日期格式化程序来实现它? 随时推荐任何第三方库或纯 Java API 解决方案。 最佳答案 使用
我的表中有两列需要添加在一起。其中之一是带有军事时间的 varchar(4),减去冒号,包括前面的 0。另一种是 int,它描述约会的持续时间(以分钟为单位)。基本上我需要将两者添加在一起并将其保留为
我在树莓派终端遇到了一个问题。 >>> alarm = input('Please input the time for the alarm in format HHMM: \n ') >>> pri
我对 Python 比较陌生 我有一列数据代表一天中的时间 - 但采用整数格式 hhmm - 即 1230、1559。 我知道应该将其转换为正确的时间格式,以便可以正确使用。 我花了一段时间在谷歌上搜
我需要验证包含时间的文本框条目。 时间应为 HH:mm 格式和 24 小时格式。 例如: 09:00, 21:00, 00:00, etc., 无效条目: 2534, 090, *7&**, etc.
是否可以计算两个“HHmm”字符串之间的分钟数或小时数。 Javascript 示例: var now = 2050, next = 0850, minutesUntilNext =
我有两个 int 变量,如下所示: int minutes = 20; int hours = 8; 我如何将它们转换为“HHMM”格式? 对于上述内容,结果应该是“0820”。 最佳答案 如果您只想
我正在尝试将日期时间移动一个“HHmm”格式的持续时间,例如“0010”表示 10 分钟。 我找到了类似的票证( Parsing time strings like "1h 30min" ),但我无法
我有一个包含纪元时间的变量。我想以 HHMM 格式显示时间。 这是我的代码; function epoch_time_to_date_obj(epoch_time) { var utcSeco
我需要与一个未实现完整 ISO 8601 且仅接受格式 +HH:mm 的时区偏移量的应用程序通信。 Android 似乎只生成带有 SampleDateFormat 中的 'z' 的 +HHmm 格式
我想将 DataGridView 列中的 TimeSpan 字段显示为 hhmm。并允许用户以这种格式对其进行编辑。据我所知,我需要向 CellFormatting、CellParsing 和 Cel
我有一个 Excel 工作表,其中一列是交易时间,其格式为 HH:MM:SS。但我需要 HHMM 格式的交易时间,以便我可以将该 Excel 工作表上传到我的应用程序中。截至目前,我正在手动格式化每一
回答这个问题 Temperature curve in R 我遇到了 dplyr::filter - lubridate::minute 组合的奇怪行为。 见下面的测试数据dta。 dta$time
我想将 hhmm 格式的时间字符串转换为 hh:mm 格式,例如 “230”将变成“2:30” “400”将变为“4:00” 我做了以下事情 var timeString = "200"; var f
我一直在寻找答案,但找不到满足我需求的确切答案。 我正在寻找将 Datetime 值转换为 YYYY-MM-DD-HHMM 格式的方法。 我试过那个: select CONVERT(varchar(2
我有一个 csv 文件,其中包含一列数据,其中每个值都是一个整数,表示一天中的小时和分钟。问题是每个值不遵循相同的格式。如果介于 12:00 AM 和 12:10 AM 之间,则该值将仅为一位数字,即
我正在编写一个相当简单的REST API,我的一个对象会想知道要激活的时间和持续时间。我希望我可以使用Actix-web、serde和chrono将ISO 8601时间/持续时间序列化为Ruust中结
我正在编写一个相当简单的REST API,我的一个对象会想知道要激活的时间和持续时间。我希望我可以使用Actix-web、serde和chrono将ISO 8601时间/持续时间序列化为Ruust中结
我是一名优秀的程序员,十分优秀!