I am trying to follow this post but I am not sure how to store my data in the iso8601 format because I am not getting any "seconds" input from the timepicker interface, can I just append "0000" to the end of the string builder?
The post also uses SimpleDateFormat() which is supported for API 24 only. My minimum API level is 19. Is there an equivalent function for it?
Java Code:
public void saveExam() {
date = (DatePicker)findViewById(R.id.examDate);
Integer day = date.getDayOfMonth();
Integer month = date.getMonth();
Integer year = date.getYear();
time = (TimePicker)findViewById(R.id.examTime);
Integer hour, minutes;
if (Build.VERSION.SDK_INT >= 23 ) {
hour = time.getHour();
minutes = time.getMinute();
} else {
hour = time.getCurrentHour();
minutes = time.getCurrentMinute();
}
StringBuilder temp = new StringBuilder();
temp.append(year.toString()).append("-").append(month.toString()).append("-").append(day.toString())
.append(" ").append(hour).append(":").append(minutes);
Toast.makeText(add_exam.this, temp, Toast.LENGTH_LONG).show();
}
Could someone also please explain to me this part of the code, this is my first time seeing flags:
if (date != null) {
long when = date.getTime();
int flags = 0;
flags |= android.text.format.DateUtils.FORMAT_SHOW_TIME;
flags |= android.text.format.DateUtils.FORMAT_SHOW_DATE;
flags |= android.text.format.DateUtils.FORMAT_ABBREV_MONTH;
flags |= android.text.format.DateUtils.FORMAT_SHOW_YEAR;
finalDateTime = android.text.format.DateUtils.formatDateTime(context,
when + TimeZone.getDefault().getOffset(when), flags);