get Minutes Duration - Java java.util

Java examples for java.util:Minute

Description

get Minutes Duration

Demo Code


import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main{
    public static void main(String[] argv) throws Exception{
        int field = 2;
        System.out.println(getMinDuration(field));
    }// www . j a va 2  s  . c o  m
    public static final long SECOND_ms = 1000;
    public static final long MINUTE_ms = 60 * SECOND_ms;
    public static final long HOUR_ms = 60 * MINUTE_ms;
    public static final long DAY_ms = 24 * HOUR_ms;
    public static final long WEEK_ms = DateTime.calendarInstance()
            .getLeastMaximum(Calendar.DAY_OF_WEEK) * DAY_ms;
    public static final long MONTH_ms = DateTime.calendarInstance()
            .getLeastMaximum(Calendar.DAY_OF_MONTH) * DAY_ms;
    public static final long YEAR_ms = DateTime.calendarInstance()
            .getLeastMaximum(Calendar.DAY_OF_YEAR) * DAY_ms;
    public static long getMinDuration(int field) {
        switch (field) {
        case Calendar.YEAR:
            return YEAR_ms;
        case Calendar.MONTH:
            return MONTH_ms;
        case Calendar.WEEK_OF_YEAR:
            return WEEK_ms;
        case Calendar.DAY_OF_WEEK:
            return DAY_ms;
        case Calendar.DAY_OF_MONTH:
            return DAY_ms;
        case Calendar.HOUR_OF_DAY:
            return HOUR_ms;
        case Calendar.MINUTE:
            return MINUTE_ms;
        case Calendar.SECOND:
            return SECOND_ms;
        }
        return -1;

    }
}

Related Tutorials