Java Code Examples for java.util.GregorianCalendar#MILLISECOND

The following examples show how to use java.util.GregorianCalendar#MILLISECOND . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TimeScales.java    From diirt with MIT License 6 votes vote down vote up
static TimePeriod toTimePeriod(double seconds) {
    if ( seconds >= 36288000 ) {
        return new TimePeriod( GregorianCalendar.YEAR , seconds/3024000 );
    }
    if ( seconds >= 3024000 ) {
        return new TimePeriod( GregorianCalendar.MONTH , seconds/3024000 );
    }
    if ( seconds >= 604800 ) {
        return new TimePeriod( WEEK_FIELD_ID , seconds/604800.0 );
    }
    if ( seconds >= 86400 ) {
        return new TimePeriod( DAY_FIELD_ID , seconds/86400.0 );
    }
    if ( seconds >= 3600 ) {
        return new TimePeriod( HOUR_FIELD_ID , seconds/3600.0 );
    }
    if (seconds >= 60) {
        return new TimePeriod(GregorianCalendar.MINUTE, seconds / 60.0);
    }
    if (seconds >= 1) {
        return new TimePeriod(GregorianCalendar.SECOND, seconds);
    }
    return new TimePeriod(GregorianCalendar.MILLISECOND, 1000*seconds);
}
 
Example 2
Source File: TimeScales.java    From diirt with MIT License 4 votes vote down vote up
static void round(GregorianCalendar cal, int field) {

        if (GregorianCalendar.MILLISECOND == field) {
            return;
        }
        cal.set(GregorianCalendar.MILLISECOND, 0);

        if (GregorianCalendar.SECOND == field) {
            return;
        }
        cal.set(GregorianCalendar.SECOND, 0);

        if (GregorianCalendar.MINUTE == field) {
            return;
        }
        cal.set(GregorianCalendar.MINUTE, 0);

        if ( HOUR_FIELD_ID == field ) {
            return;
        }
        cal.set( HOUR_FIELD_ID , FIRST_HOUR );

        if ( DAY_FIELD_ID == field ) {
            return;
        }
        cal.set(DAY_FIELD_ID , FIRST_DAY );

        if ( WEEK_FIELD_ID == field ) {
            return;
        }

        //here, we are rounding down to the first week (i.e. the first day of
        //the month), so the day of the week and the week of the month no
        //longer matter - we just set the day to be the first day of the month
        cal.set( GregorianCalendar.DAY_OF_MONTH , 1 );

        if ( GregorianCalendar.MONTH == field ) {
            return;
        }

        cal.set( GregorianCalendar.MONTH , 0 );

        if ( GregorianCalendar.YEAR == field ) {
            return;
        }
        cal.set( GregorianCalendar.YEAR , 0 );

    }