【问题标题】:sunrise and sunset timezone using openweathermap api使用 openweathermap api 的日出和日落时区
【发布时间】:2017-03-10 22:00:28
【问题描述】:

我如何以这种方式更改时间格式 日出 6:00 和日落 17:66 {"type":1,"id":5091,"message":0.0102,"country":"GB","sunrise ":1489127014,"日落":1489168699}

【问题讨论】:

    标签: android android-studio


    【解决方案1】:

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

    /**
     * @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 对象传递:Date dateObject = new Date(yourTimeInMilliseconds);

    【讨论】:

      【解决方案2】:

      请在下面的 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))
      

      请随时评论您的评论。

      【讨论】:

      • 鉴于问题是关于 Android 的,我认为这不是很有帮助。
      猜你喜欢
      • 1970-01-01
      • 2015-01-03
      • 2019-06-21
      • 1970-01-01
      • 1970-01-01
      • 2016-12-23
      • 2011-06-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多