java - 如何在 kotlin 或 java 中计算祈祷时间?
问题描述
所以我使用这个类: http ://praytimes.org/code/git/?a=viewblob&p=PrayTimes&h=093f77d6cc83b53fb12e9900803d5fa75dacd110&hb=HEAD&f=v1/java/PrayTime.java 来获取祈祷时间,我想用它我使用位置权限制作的纬度和经度,但是当我更改时区的值时,我并没有给我准确的城市祈祷时间。有没有办法让时区自动工作?所以如果摩洛哥的一个人使用我的应用程序,时区会自动更改为摩洛哥时区,所以祈祷时间会给出准确的时间?同样,如果一个人住在沙特、伊拉克、西班牙……等
提前致谢。
**我的代码有问题**
@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 用于示例
解决方案
对于获取时区,您可以轻松使用此库:https ://raw.githubusercontent.com/drtimcooper/LatLongToTimezone/master/src/main/java/com/skedgo/converter/TimezoneMapper.java之后使用TimeZone.getTimeZone
也用于计算祈祷时间,这个网站的代码很有用http://praytimes.org/code/
推荐阅读
- python - “[Float64Index([nan, nan], dtype='float64')] 中没有一个在 [index] 中”如果 col B 包含字符串,则设置 col A 值
- c# - 使用 Autofac 实现 N 层架构时获取空参数
- moodle - 在 R/exams 中为考试添加介绍页面
- javascript - 未处理的拒绝:动作未定义 React js 和 Redux
- node.js - 听 EADDRINUSE:地址已经在使用 -> 不管我使用什么端口?
- sql - 如何使用 WP Query 编写内部联接
- r - 缺少功能:在 R 中分离
- php - 当购物车中已经有超过 5 个“product_cat”时,限制“product_cat”的购物车添加(Woocommerce)
- vba - 将邮件移动到带有发件人姓名的文件夹
- c++ - c++ 为什么我不应该从不同的线程解锁互斥锁