将字符串日期转换为警报

时间:2013-02-17 15:37:48

标签: java android eclipse

我正在尝试设置闹钟。我有时间存储在cvs文件中。它们的格式为hh:mm,例如02:13。我想在这个时候设置闹钟

使用以下代码

  SimpleDateFormat  dt = new SimpleDateFormat("hh:mm"); 
      dt.parse(str); // GET TIME HERE

NotificationManager manger = (NotificationManager) this.getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
        Notification notification = new Notification(R.drawable.launcher, "Mosque Prayer Times", time);
        PendingIntent contentIntent = PendingIntent.getActivity(this.getActivity(), 0, new Intent(this.getActivity(), AlarmReceiver.class), 0);
        notification.setLatestEventInfo(this.getActivity(), name, title, contentIntent);
        notification.flags = Notification.FLAG_INSISTENT;
        notification.sound = Uri.parse("android.resource://com.trib.app.mosqueprayertimes/raw/adhan.mp3");
        manger.notify(id, notification);        
    }

我发现如何从这个日期格式中提取“时间”并将其设置在我的通知中

很困难

1 个答案:

答案 0 :(得分:0)

你试过这个......

 SimpleDateFormat  dt = new SimpleDateFormat("hh:mm"); 
     Date date=  dt.parse(str); // GET TIME HERE
    Calender cal=Calender.getInstance();
    cal.setTime(date);
    String hours=cal.get(Calendar.HOUR);
    String minutes=cal.get(Calendar.MINUTE);