java - using joda time to get milliseconds value depending on time unit and ammount

188 views Asked by At

I have a String representing unit of time ("days"/"hours"/"minutes") and a value representing the amount , so, for example, I have 6 and "days", which means 6 days ago (time unit and amount can vary, and together they mean some time ago).

What I want, using joda time, is to give a int value to each one of those combinations representing the epoch of that time (so, for example, get the epoch of 6 days ago, or 5 minutes ago).

How can I achieve that? I do have a map that looks like this:

private Map<String, DurationFieldType> durationFieldTypeMap = new HashMap<String, DurationFieldType>() {{
        put("minutes", DurationFieldType.minutes());
        put("hours", DurationFieldType.hours());
        put("days", DurationFieldType.days());
    }};

Is that the way to do? how can I calculate the epoch based on the time unit and amount?

0

There are 0 answers