【发布时间】:2020-02-16 05:31:08
【问题描述】:
我正在尝试转换 openweathermap 提供的毫秒格式的时间,但是当我转换它们时,时间仅相隔 1 分钟。
我已尝试使用Simpledateformat 进行转换。
fun formatTIme(sun:Date):String{
val timeformat:SimpleDateFormat= SimpleDateFormat("h:m a")
return timeformat.format(sun)
}
sys": {
"type": 1,
"id": 9201,
"message": 0.0075,
"country": "NP",
"sunrise": 1571444437,
"sunset": 1571485599
},
"timezone": 20700,
"id": 1282682,
"name": "Thapathali",
"cod": 200
}
API call is done through Nepal 如果有帮助的话。
为什么时间只有1分钟的差异?
谁能帮帮我
【问题讨论】:
-
您如何将这些时间戳转换为日期?另请注意,
m日期格式字符是月份,而不是分钟。 -
@laalto 使用 currentmillis.com 网站
-
您的输入以秒为单位,而不是毫秒。乘以 1000 以获得更好的结果。
-
乘以千工作。谢谢
-
顺便考虑扔掉长期过时且臭名昭著的麻烦
SimpleDateFormat和朋友,并将ThreeTenABP添加到您的Android项目中,以便使用java.time,现代Java日期和时间API .使用起来感觉好多了。
标签: java android android-studio unix-timestamp openweathermap