gpt4 book ai didi

java - 如何使用Kotlin或Java计算祷告时间?

转载 作者:行者123 更新时间:2023-12-02 12:51:21 33 4
gpt4 key购买 nike

所以我正在使用此类:
http://praytimes.org/code/git/?a=viewblob&p=PrayTimes&h=093f77d6cc83b53fb12e9900803d5fa75dacd110&hb=HEAD&f=v1/java/PrayTime.java
以获得祈祷时间,我想将其与经位置许可的纬度和经度一起使用,但是每当更改时区的值时,我都无法为我提供城市的准确祈祷时间。
有什么办法可以使时区自动工作?因此,如果摩洛哥的某个人使用我的应用程序,则时区会自动更改为摩洛哥时区,以便祈祷时间能提供准确的时间?同样,如果一个人住在沙特,伊拉克,西类牙..etc

提前致谢。

**我的代码有问题**

@SuppressLint("MissingPermission")
private fun getLastLocation() {
if (checkPermission()) {
if (isLocationEnabled()) {

mFusedLocationClient.lastLocation.addOnCompleteListener(this) { task ->
var location: Location? = task.result
if (location == null) {
requestNewLocationData()
} else {

val resultimeZone = TimezoneMapper.latLngToTimezoneString(
location.latitude,
location.longitude
)
findViewById<TextView>(R.id.cityName).text = resultimeZone
val latitude: Double = location.latitude
val longitude: Double = location.longitude
var timeZone = 3.00
val timeZoneId = timeZone.toString()
val prayTime = praytime()
prayTime.timeFormat = prayTime.time12 // getTime12 is protected
prayTime.calcMethod = prayTime.makkah // Makkah
prayTime.asrJuristic = prayTime.shafii // Shafii (standard)
prayTime.adjustHighLats = prayTime.angleBased
prayTime.timeZone = prayTime.timeZone
prayTime.computeMidDay(prayTime.dhuhrMinutes.toDouble())
val offsets = intArrayOf(
0,
0,
0,
0,
0,
0,
0
) // {Fajr,Sunrise,Dhuhr,Asr,Sunset,Maghrib,Isha}

prayTime.tune(offsets)
val cal = Calendar.getInstance(TimeZone.getTimeZone(timeZoneId))
cal.time = Date()


val times: ArrayList<String> =
prayTime.getPrayerTimes(
cal,
latitude,
longitude,
timeZone
)
findViewById<TextView>(R.id.Fajr).text = times.get(0)
findViewById<TextView>(R.id.sabah).text = times.get(1)
findViewById<TextView>(R.id.dhuhr).text = times.get(2)
findViewById<TextView>(R.id.AzanTime).text = times.get(3)
findViewById<TextView>(R.id.maghreb).text = times.get(4)
findViewById<TextView>(R.id.Esha).text = times.get(6)

}
}
} else {
Toast.makeText(this, "Turn on location", Toast.LENGTH_LONG).show()
val intent = Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)
startActivity(intent)
}
} else {
requestPermission()
}

您可以使用Java For Samples

最佳答案

要获取时区,您可以轻松地使用此库:https://raw.githubusercontent.com/drtimcooper/LatLongToTimezone/master/src/main/java/com/skedgo/converter/TimezoneMapper.java之后使用TimeZone.getTimeZone另外,为了计算祈祷时间,此站点的代码也很有用http://praytimes.org/code/

关于java - 如何使用Kotlin或Java计算祷告时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61429035/

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