我的数据库中有一个值,此时间格式为“上午10:40”,现在我将使用它到闹钟管理器,这是我的报警管理员代码。Android:我如何将上午和下午格式的时间转换为整数秒
Long alertTimeCatcher = new GregorianCalendar().getTimeInMillis()+10*1000;
+10*1000
我想改变10内与我“上午10点40分”的双引号,所以我要把它转换为整数。我该怎么做?
让刚刚说我有 “11:40 AM” 我将它转换成整数
INT时间= “11:40 AM”;
这是原来的代码,然后
Long alertTimeCatcher = new GregorianCalendar().getTimeInMillis()+10*1000;
那么这就是我需要
Long alertTimeCatcher = new GregorianCalendar().getTimeInMillis()+Time*1000;
所以为了触发我报警经理,我需要我的时间转换为整数。
这是我到目前为止尝试过的。
try {
Cursor c = myDB.rawQuery("SELECT * FROM " + "tblEvents", null);
int Column2 = c.getColumnIndex("Date");
int Column3 = c.getColumnIndex("Time");
String[] arr = new String[0];
// Check if our result was valid.
ArrayList<String> list = new ArrayList<String>();
c.moveToFirst();
if (c != null) {
// Loop through all Results
do {
String Date = c.getString(Column2);
String Time = c.getString(Column3);
Calendar ca = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("M/dd/yyyy");
String formattedDate = df.format(ca.getTime());
if (Date.equalsIgnoreCase(formattedDate)) {
list.add(Time);
Toast.makeText(getApplicationContext(), "Converter : ", Toast.LENGTH_SHORT).show();
}
} while (c.moveToNext());
}
Collections.reverse(list);
}catch(CursorIndexOutOfBoundsException e){
e.printStackTrace();
}
Long alertTimeCatcher = new GregorianCalendar().getTimeInMillis()+10*1000;
Toast.makeText(getApplicationContext(),alertTimeCatcher.toString(),Toast.LENGTH_SHORT).show();
Intent alertIntent = new Intent(this,AlertReceiver.class);
AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP,alertTimeCatcher,PendingIntent.getBroadcast(this,1,alertIntent,PendingIntent.FLAG_UPDATE_CURRENT));
的[“HH:MM AM/PM”转换时间值来格式化使用Android]可能的复制(http://stackoverflow.com/questions/16084474/convert-time-value-to-format -hhmm-am-pm-using-android) –