Java 将字符串日期转换为报警
我正在试着设置闹钟。我将时间存储在cvs文件中。它们的格式为hh:mm,例如02:13。我想为这次设置闹钟 使用以下代码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
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
方法。而且,在这里使用会更有帮助。