gpt4 book ai didi

android - Kotlin 检查变量是否在两个数字之间

转载 作者:行者123 更新时间:2023-12-02 16:20:28 24 4
gpt4 key购买 nike

我有来自 LocalTime.now() 的当前时间。我想使用当前时间检查两个 double 字之间是否存在但我无法将时间转换为 double

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

val CurrentTime = LocalTime.now().format(DateTimeFormatter.ofPattern("HH.mm"))

tvDetailIcon = view.findViewById(R.id.tvDetailIcon)
testTime = view.findViewById(R.id.testTime)
testTime.text = CurrentTime


if (24.00<testTime && testTime<25.00 ){
constraint.setBackgroundColor(Color.parseColor("#34495e"))
tvDetailIcon.setImageResource(R.drawable.ic_baseline_nights_stay_24)
}

else if (1.00<testTime && testTime<24.00){
constraint.setBackgroundColor(Color.parseColor("#349Bdb"))
tvDetailIcon.setImageResource(R.drawable.ic_baseline_wb_sunny_72)

}

You can find fail here.

最佳答案

条件是检查是否在两个数字之间

val number = 5
val min = 2
val max = 10

if(number in min..max){
Log.i("Yes, number is between min and max")
} else{
Log.i("No, number is not between min and max")
}

关于android - Kotlin 检查变量是否在两个数字之间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65637680/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com