0

I'm a volunteer trying to create an app for a local organization that assists people with recovery, employment, support, and training called REST please help me. I created this class to represent time as a prototype. What I need is how to represent an example such as: 1:45 PM - 2:35 PM, 8 AM - 8:30 AM, and so on. I need this solution to work on minimumSdk 21 as Duration requires api 26 and that will not do because the app will not be compatible with most device.

import java.time.LocalTime;
import java.time.Duration;

class JavaTime {
    private String local;

    public JavaTime() {
    }

    public static void main(String[] args) {

        JavaTime java_time = new JavaTime();

        java_time.local = LocalTime.MIN.plus(Duration.ofMinutes(260L)).toString();
        System.out.println(java_time.local);
    }
}

Output:4:20

Here is the method I need to finish in the database:

public void getMondayGroup(int id) {
        SQLiteDatabase db = this.getReadableDatabase();

        Cursor cursor = db.query(DBUtil.MONDAY_TABLE,
                new String[]{DBUtil.KEY_ID,
                        DBUtil.KEY_GROUP_NAME,
                        DBUtil.KEY_GROUP_DAY,
                        DBUtil.KEY_START_TIME,
                        DBUtil.KEY_END_TIME},
                DBUtil.KEY_ID + "=?",
                new String[]{String.valueOf(id)},null,null,null,null);

        if (cursor != null) {
            cursor.moveToFirst();
        }

        Groups groups = new Groups();
        if(cursor != null) {
            groups.setId(Integer.parseInt(cursor.getString(cursor.getColumnIndex(DBUtil.KEY_ID))));
            groups.setGroupName(cursor.getString(cursor.getColumnIndex(DBUtil.KEY_GROUP_NAME)));
            groups.setGroupDay(cursor.getString(cursor.getColumnIndex(DBUtil.KEY_GROUP_DAY)));
            groups.setGroupStartTime(cursor.getString(cursor.getColumnIndex(DBUtil.KEY_START_TIME)));
            groups.setGroupEndTime(cursor.getString(cursor.getColumnIndex(DBUtil.KEY_END_TIME)));

            // Issue
            String local = local_time.MIN.plus(Duration.ofMinutes(260L)).toString();

            // I want to replace this date with time
            DateFormat dateFormat = DateFormat.getDateInstance();
            String formattedDate = dateFormat.format(new Date(cursor.getLong(
                    cursor.getColumnIndex(DBUtil.KEY_START_TIME)).getTime()); // Feb 23, 2020
            groups.setDateCreated(formattedDate);*/
        }
    }
  • 1
    Does this answer your question? [cannot resolve symbol 'java.time.LocalDate' error in android studio](https://stackoverflow.com/questions/28745205/cannot-resolve-symbol-java-time-localdate-error-in-android-studio) Or this? [OffsetDateTime.now() requires API 26](https://stackoverflow.com/questions/49348769/offsetdatetime-now-requires-api-26) Or [this](https://stackoverflow.com/questions/54828832/zoneddatetime-to-date-before-java-8-in-early-android)? – Ole V.V. Apr 07 '20 at 03:18
  • 1
    I don’t think I’d want to bother to build my own `JavaTime` class. I’d just use `LocalTime` directly. – Ole V.V. Apr 07 '20 at 03:33
  • I dug through the posts and ran into ThreeTenABP which seems to be a possible solution but I'm not sure how to implement it. There are a lot of classes and uses which are not straightforward to me. – Wesley Ruede Apr 08 '20 at 20:11
  • 1
    There are many classes alright. I think that `org.threeten.bp.LocalTime` is fine for your purpose. A detail, it may be easier to do `LocalTime.MIN.plusMinutes(260)` and not use `Duration`. Beware of cyclic overflow, `LocalTime.MIN.plusMinutes(1500)` gives 01:00 (not 25:00 because that time doesn't exist). – Ole V.V. Apr 09 '20 at 08:47
  • 1
    Yes that worked perfectly I'll post my answer with the code. Thank you very much for your help. – Wesley Ruede Apr 15 '20 at 20:54

0 Answers0