检查android时间间隔之间的当前时间
我想创建一个应用程序,允许用户检查当前时间是否落在指定的时间间隔之间。更具体地说,我使用 sqllite 程序创建了一个 sql 表,该表指定每个记录的结束时间和开始时间。问题在于每个字段的数据类型仅限于文本、数字和日期时间类型以外的其他类型。那么,我如何能够检查当前时间是否在开始时间和结束时间之间,因为时间格式为 h:mm 而不仅仅是一个我可以小于或大于的整数值?我必须将当前时间转换为分钟吗?
I want to create an app that will allow the user to check whether or not the current time falls between a specified time interval. More specifically, I created a sql table using sqllite program, with the table specifying an end time and a start time for each record. The problem is that the type of data each field can be is limited to text, number, and other type other than a datetime type. So, how would I be able to check if the current time is between the start and end time since the format of time is in h:mm and not just an integer value that I could just do less than or greater than? Do I have to convert the current time to minutes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
即使时间未存储在日期时间类型中,您也应该能够进行比较,这里是一个解释从字符串到时间转换的链接。
如果这不起作用,请将时间转换为秒 (int) 并计算差值。
You should be able to do the comparison even if time is not stored in the datetime type, here is a link that explains the conversion from string to time.
If that doesn't work, convert the time to seconds (int) and calculate the difference.
试试这个。您可以将时间保存和检索为字符串:
然后,您使用此过程来检查时间:
在您的主程序中像这样检查它:
我希望它有帮助。
Try this. You can save and retrieve your time as String:
Then, you use this procedure to check time:
And in your main program check it like this:
I hope it helps.