Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将字符串日期转换为报警_Java_Android_Eclipse - Fatal编程技术网

Java 将字符串日期转换为报警

Java 将字符串日期转换为报警,java,android,eclipse,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(Contex

我正在试着设置闹钟。我将时间存储在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);        
    }

我发现很难从这个日期格式中提取“时间”并在我的通知中设置它

您尝试过这个吗

 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);

没有
Date 35; getTime()
工作吗?我想用不同的小时和分钟获取当前日期。您可以设置当前日期的小时和分钟,然后使用
getTime
方法。而且,在这里使用会更有帮助。