Assigning an Android calendar to start and end

I have an application with an agenda with a list of time and date. When a user clicks on one of these events, the goal of the calendar should begin, so you need to open the calendar with the time, date and reminder. However, when I upload the intention, the start time is only the current time, and the end time is an hour ahead. Can someone please tell me what I'm doing wrong. Here is an example of a hard coded calendar with setting the date and time. I am testing with

Calendar startDate = Calendar.getInstance(); startDate.set(Calendar.MONTH, 8); startDate.set(Calendar.YEAR, 2012); startDate.set(Calendar.DAY_OF_MONTH, 5); startDate.set(Calendar.HOUR_OF_DAY, 9); // Set the calendar Calendar endDate = Calendar.getInstance(); endDate.set(Calendar.MONTH, 8); endDate.set(Calendar.YEAR, 2012); endDate.set(Calendar.DAY_OF_MONTH, 5); endDate.set(Calendar.HOUR_OF_DAY, 15); endDate.set(Calendar.MINUTE, 30); Intent intent = new Intent(Intent.ACTION_EDIT); intent.putExtra("calendar_id", 1); intent.setType("vnd.android.cursor.item/event"); intent.putExtra("beginTime", startDate.getTime()); intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.putExtra("allDay", false); intent.putExtra("endTime", endDate.getTime()); intent.putExtra("title", "A Test Event from android app"); intent.putExtra("description", "Your consulting date and time"); startActivity(intent); 
+4
source share
1 answer

After a lot of searching. I found this method. Bit annoying but it works

 java.sql.Timestamp tsStart = java.sql.Timestamp.valueOf(year+ "-" + month + "-" + day + " " + hour + ":"+ minute + ":00"); java.sql.Timestamp tsStart = java.sql.Timestamp.valueOf(year+ "-" + month + "-" + day + " " + hour2+ ":"+ minute2+ ":00"); long startTime = tsStart.getTime(); long endTime = tsEnd.getTime(); 

I was just hoping I could use the Calendar method to set the date and time, although guessing really doesn't matter. Also customize people using this method, make sure your month to month fields, etc. Conform to timestamp format. In my application, when I clicked on the agenda, a date and time string would be required for that date, and then I split it like this:

 String array[] = tvSessionTime.getText().toString().split(" "); String array2[] = array[0].split(":"); int iHour = Integer.parseInt(array2[0]) int sMinute = Integer.parseInt(array2[0]) String array3[] = tvSessionDate.getText().toString().split(" "); 

And if you had time, like 07.05, and you sorted out the hour, the hour will return as 7, and the minute will return as 5. And the format will be yyyy-hh-mm. So this led to an error, as it did not match the date format. Just a head!

+1
source

All Articles