使用openweathermap api的日出和日落时区

时间:2017-03-10 22:00:28

标签: android android-studio

我如何以这种方式改变时间格式日出6:00和日落17:66 {"键入":1," id":5091,"消息&# 34;:0.0102,"国家":" GB""日出":1489127014,"日落":1489168699}

2 个答案:

答案 0 :(得分:0)

您可以使用此方法更改时间:

€

并以/** * @param dateObject value of time * @return formatted time */ public static String formatTime(Date dateObject) { SimpleDateFormat timeFormat = new SimpleDateFormat("h:mm a"); return timeFormat.format(dateObject); } 对象传递:Date

答案 1 :(得分:0)

请在pyhton中找到以下示例代码以供您参考。 (请包括“日期时间”模块)

from datetime import datetime
timezone = int(data['timezone'])
print('Timezone : {}'.format(timezone))

sunrise_utc = int(data['sys']['sunrise'])
sunrise_local = datetime.utcfromtimestamp(sunrise_utc + timezone).strftime('%H-%M-%S')
print('Sunrise : {}'.format(sunrise_local))

sunset_utc = int(data['sys']['sunset'])
sunset_local = datetime.utcfromtimestamp(sunset_utc + timezone).strftime('%H-%M-%S')
print('sunset : {}'.format(sunset_local))

请随时评论您的评论。