0

/{"chogadia":[{"ChogadiaName":5,"StartTime":"5:25:50 AM","EndTime":"7:9:13 AM","Effect":"不祥的 Chogadia"},{ "ChogadiaName":6,"StartTime":"7:9:13 AM","EndTime":"8:52:37 AM","Effect":"吉祥的 Chogadia"},{"ChogadiaName":7," StartTime":"8:52:37 AM","EndTime":"10:36:1 AM","Effect":"Inauspicious Chogadia"},{"ChogadiaName":1,"StartTime":"10:36 :1 AM","EndTime":"12:19:24 AM","Effect":"Inauspicious Chogadia"},{"ChogadiaName":2,"StartTime":"12:19:24 PM","EndTime ":"14:2:48 PM","效果":"吉祥的 Chogadia"},{"ChogadiaName":3,"StartTime":"14:2:48 PM","EndTime":"15:46:12 PM","Effect":"吉祥的 Chogadia"},{" ChogadiaName":4,"StartTime":"15:46:12 PM","EndTime":"17:29:36 PM","Effect":"吉祥的 Chogadia"},{"ChogadiaName":5,"StartTime ":"17:29:36 PM","EndTime":"19:13:0 PM","效果":"不祥的 Chogadia"},{"ChogadiaName":3,"StartTime":"19:13: 0 PM","EndTime":"20:29:36 PM","Effect":"吉祥 Chogadia"}]}吉祥圆顶"},{"圆顶名称":4,"StartTime":"15:46:12 PM","EndTime":"17:29:36 PM","效果":"吉顶"},{" ChogadiaName":5,"StartTime":"17:29:36 PM","EndTime":"19:13:0 PM","Effect":"不吉利的 Chogadia"},{"ChogadiaName":3,"StartTime ":"19:13:0 PM","EndTime":"20:29:36 PM","Effect":"吉祥乔加迪亚"}]}吉祥圆顶"},{"圆顶名称":4,"StartTime":"15:46:12 PM","EndTime":"17:29:36 PM","效果":"吉顶"},{" ChogadiaName":5,"StartTime":"17:29:36 PM","EndTime":"19:13:0 PM","Effect":"不吉利的 Chogadia"},{"ChogadiaName":3,"StartTime ":"19:13:0 PM","EndTime":"20:29:36 PM","Effect":"吉祥乔加迪亚"}]}Effect":"不祥的 Chogadia"},{"ChogadiaName":3,"StartTime":"19:13:0 PM","EndTime":"20:29:36 PM","Effect":"吉祥的 Chogadia" }]}Effect":"不祥的 Chogadia"},{"ChogadiaName":3,"StartTime":"19:13:0 PM","EndTime":"20:29:36 PM","Effect":"吉祥的 Chogadia" }]}/

公共类 ChogadiaParser {

public static  ArrayList<Chogadia> mList=new ArrayList<Chogadia>();
public static Chogadia mChogadia;
public static String response,chogadia;
public static String Lucky="Auspicious Chogadia";
public static String UnLucky="Inauspicious Chogadia";
public static String chogadiaName,startTime,endTime;


public static void GroupResult(String url){

    try{
      JSONArray jArray;
      JSONObject jObject;

     response=GetJsonObject.sendRequest(url);

     if(response == null){
            return;
        }

     jObject=new JSONObject(response);
     jArray=jObject.getJSONArray("chogadia");
     mList.clear();
     for(int i=0;i<jArray.length();i++){

         mChogadia=new Chogadia();
         jObject=jArray.getJSONObject(i);
         mChogadia.SetChogadiaName(jObject.getString("ChogadiaName"));
         mChogadia.SetStartTime(jObject.getString("StartTime"));
         mChogadia.SetEndTime(jObject.getString("EndTime"));
         mChogadia.SetEffect(jObject.getString("Effect"));
         mList.add(mChogadia);



         if(mathcTime(jObject.getString("StartTime"),jObject.getString("EndTime"))){

              chogadiaName=jObject.getString("ChogadiaName");
              startTime=jObject.getString("StartTime");
              endTime=jObject.getString("EndTime");
              System.out.println("Matched Name Is: " + jObject.getString("ChogadiaName")+"" + jObject.getString("StartTime") );
              Log.e("String time", jObject.getString("ChogadiaName"));


         }
     } 

    }catch(Exception e){
        e.printStackTrace();    
    }

}

   private static boolean mathcTime(String stime,String eTime) {
    SimpleDateFormat ft = new SimpleDateFormat("hh:mm:ss");

    try {
        Date ct = new Date();
        Date st = ft.parse(stime);
        Date et=ft.parse(eTime);;

        long currentTime = ((ct.getHours()*60)*60) + (ct.getMinutes()*60) + (ct.getSeconds());
        long startTime = ((st.getHours()*60)*60) + (st.getMinutes()*60) + (st.getSeconds());
        long endTime = ((et.getHours()*60)*60) + (et.getMinutes()*60) + (et.getSeconds());

        if(currentTime>=startTime && currentTime<=endTime){
            return true;
        }else{
            return false;
        }
    } catch (Exception e) {
    }
 return false;
}

请帮我解决这个问题...这里我匹配的设备等于获取时间(获取时间显示为上侧的注释)并显示 chogadiaName.it 正在工作但 prblm 不是匹配时间 AM 它开始仅从 PM 匹配..请帮助我。

4

1 回答 1

0

try date format like this

SimpleDateFormat ft = new SimpleDateFormat("hh:mm:ss a");

for more details Oracle Doc

于 2013-09-06T05:26:35.760 回答