java.util.GregorianCalendar#SECOND源码实例Demo

下面列出了java.util.GregorianCalendar#SECOND 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: diirt   文件: TimeScales.java
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);
}
 
源代码2 项目: diirt   文件: TimeScales.java
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 );

    }