【发布时间】:2014-11-07 15:33:57
【问题描述】:
我是 java 新手,我正在制作一个天气应用程序。
我从 openweathermap 服务器获取 JSON 格式的数据。下面是格式
"sys":{
"type":1,
"id":7758,
"message":0.2194,
"country":"India",
"sunrise":1410569741,
"sunset":1410614119
},
我想从中提取日出和日落,但我想要的只是时间而不是日期。 下面是我的代码
DateFormat df = DateFormat.getDateTimeInstance();
String sunrise= df.format(new Date(json.getJSONObject("sys").getLong("sunrise")*1000).getTime());
String sunset = df.format(new Date(json.getJSONObject("sys").getLong("sunset")*1000).getTime());
我的代码的问题是它给了我时间和日期,输出是 “2014 年 9 月 13 日上午 6:25:41”用于日出。日落也是如此。 ?
我该如何提取“6:25:41 AM”呢?我只想要时间而不是年/月/日
【问题讨论】:
-
发帖前请搜索 StackOverflow。
标签: java date unix-timestamp