private void getSelectedTime(final String json){
Calendar now = Calendar.getInstance();
int year = now.get(Calendar.YEAR);
int month = now.get(Calendar.MONTH); // Note: zero based!
int day = now.get(Calendar.DAY_OF_MONTH);
int hour = now.get(Calendar.HOUR_OF_DAY);
int minute = now.get(Calendar.MINUTE);
int second = now.get(Calendar.SECOND);
int millis = now.get(Calendar.MILLISECOND);
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm");
JSONArray list;
JSONObject jsonObject;
try {
jsonObject = new JSONObject(json);
list = jsonObject.getJSONArray("3");
StringTokenizer tokenizer = new StringTokenizer(list.get(0).toString(),"-");
String startTime = tokenizer.nextToken();
String endTime = tokenizer.nextToken();
String temp1 = year+"/"+month+"/"+day+" "+startTime;
String temp2 = year+"/"+month+"/"+day+" "+endTime;
System.out.println("temp1="+temp1);
System.out.println("temp2="+temp2);
Date date1 = dateFormat.parse(temp1); // temp1=2012/5/25 03:00
Date date2 = dateFormat.parse(temp2); //temp2=2012/5/25 03:06
System.out.println("Year1="+date1.getYear());
System.out.println("Month1="+date1.getMonth());
System.out.println("Day1="+date1.getDay());
System.out.println("Hour1="+date1.getHours());
System.out.println("Minutes1="+date1.getMinutes());
} catch (JSONException e) {
e.printStackTrace();
}
catch (ParseException e) {
e.printStackTrace();
}
}
}
私のアプリケーションでは、時間をかけて作業していますが、ここでいくつかの問題があります。以下を見てください私はこの結果を持っています。
list.get(0) = 03:00-03:06
temp1=2012/5/25 03:00
temp2=2012/5/25 03:06
しかし、私がこれをしようとしているとき
System.out.println("Year="+date1.getYear());
System.out.println("Month="+date1.getMonth());
System.out.println("Day="+date1.getDay());
System.out.println("Hour="+date1.getHours());
System.out.println("Minutes="+date1.getMinutes());
私はこの結果を得ました
Year=112
Month=4
Day=5
Hour=3
Minutes=0
結果が間違っている理由を誰かに教えてもらえますか?