I try to add an event in my calendar using this code :
Calendar calendarEvent = Calendar.getInstance();
Intent i = new Intent(Intent.ACTION_EDIT);
i.setType("vnd.android.cursor.item/event");
i.putExtra("beginTime", dataexp);
i.putExtra("allDay", true);
i.putExtra("rule", "FREQ=YEARLY");
i.putExtra("title", tip);
startActivity(i);
In the key "beginTime" I want to set a data from a variable "dataexp" which is a string formated from 08-10-2017 . In calendar I receive wrong value for beginTime.
Edit: i found a solution at this post M.Ganji answer : solution This is the code :
long givenDateString = milliseconds (datacalendar);
Calendar calendarEvent = Calendar.getInstance();
Intent i = new Intent(Intent.ACTION_EDIT);
i.setType("vnd.android.cursor.item/event");
i.putExtra("beginTime",givenDateString);
i.putExtra("allDay", true);
i.putExtra("rule", "FREQ=YEARLY");
i.putExtra("endTime", givenDateString);
i.putExtra("title", "Expira ");
startActivity(i);
public long milliseconds(String date)
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try
{
Date mDate = sdf.parse(date);
long timeInMilliseconds = mDate.getTime();
return timeInMilliseconds;
}
catch (ParseException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return 0;
}
Thanks for answers.