小编Xtr*_*per的帖子

如何在Android中比较AM/PM时间

我有一个场景

start-time = 4:15 PM
end-time = 2:00 AM 
Run Code Online (Sandbox Code Playgroud)

如果我current-time(让我们说下午9:15采用与开始或结束时间相同的格式)介于两者之间start-time,end-time然后转到screen 1其他明智的转到screen 2

我的问题是如何将" current-time更大"或"等于"与"开始时间" 进行比较,将"等于"与"结束时间"进行比较.我试过将给定的时间值转换成milliseconds比较但是current-time = 9:15 PM看起来大于'结束时间=凌晨2:00',因为凌晨2点将在午夜之后出现意味着如果在晚上9:15 =星期四然后凌晨2点将是星期五'.我经常搜索,但无法弄清楚.任何类型的帮助将不胜感激.

编辑:

当前时间,开始时间和结束时间所有值均为 String

编辑2

代码spinet:

long currentTime = getMillis("9:15 PM");

long startTime = getMillis("4:15 PM");

long endTime = getMillis("2:00 AM");//this will be the next day's time confusing part for me

if(currentTime >= startTime && currentTime <= endTime)
{
   //goto screen 1
}
else
{
  // goto screen …
Run Code Online (Sandbox Code Playgroud)

java time android calendar

2
推荐指数
1
解决办法
3838
查看次数

标签 统计

android ×1

calendar ×1

java ×1

time ×1