⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testdate.java

📁 java base64
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        boolean ok = BigDate.isValid( 1830, 2, 29 );
        System.out
                .println( "True or false: 1830/02/29 was a valid date: "
                          + ok
                          + "." );
        }
        sep();
        {
        // how many seconds between Jan 1, 1900 0:00 and Jan 1, 1970 0:00
        // i.e. difference between SNTP and Java timestamp bases.
        // No leap seconds to worry about.
        long diffInDays =
                BigDate.toOrdinal( 1970, 1, 1 ) - BigDate.toOrdinal( 1900,
                        1,
                        1 );
        long diffInSecs = diffInDays * ( 24 * 60 * 60L );
        System.out
                .println( diffInDays
                          + " days or "
                          + diffInSecs
                          + " seconds between 1900 Jan 1 and 1970 Jan 1" );
        }
        sep();
        {
        // How Many days since 1970 is today ?
        BigDate bigDate = BigDate.localToday();
        System.out
                .println( "Today is "
                          + bigDate.getOrdinal()
                          + " days since 1970" );
        }
        sep();
        {
        // How Many days since 1970 is 2000/2/29?

        BigDate bigDate = new BigDate( 2000, 2, 29 );

        System.out
                .println( "1999-12-29 is "
                          + bigDate.getOrdinal()
                          + " days since 1970" );
        }
        sep();
        {
        // How Many milliseconds since 1970 is 1999/11/7
        BigDate bigDate = new BigDate( 1999, 11, 7 );
        System.out
                .println( "1999-11-07is "
                          + bigDate.getLocalTimeStamp()
                          + " milliseconds since 1970" );
        }
        sep();
        {
        // Is the year 2000 a leap year?
        System.out
                .println( "True or false: 2000 is a leap year: "
                          + BigDate.isLeap( 2000 )
                          + "." );
        }
        sep();

        {
        // What is the last day of this week, e.g. this Saturday?
        // display yyyy/mm/dd format.
        BigDate bigDate = BigDate.localToday();
        /* 0=Sunday to 6=Saturday */
        bigDate.addDays( 6 - bigDate.getDayOfWeek() );
        System.out.println( "This Saturday is " + bigDate.toString() + "." );
        }
        sep();
        {
        // In what week number did 1999/08/20 fall?

        BigDate bigDate = new BigDate( 1999, 8, 20 );
        System.out
                .println( "1999/08/20 fell in ISO week number "
                          + bigDate.getISOWeekNumber()
                          + " on ISO day of week number "
                          + bigDate.getISODayOfWeek()
                          + "." );

        System.out
                .println(
                        " According to BigDate.getWeekNumber that is week number "
                        + bigDate.getWeekNumber() );

        GregorianCalendar g = new GregorianCalendar( 1999, 8 - 1, 20 );
        System.out
                .println(
                        " According to java.util.Calendar that is week number "
                        + g.get( Calendar.WEEK_OF_YEAR )
                        + "." );
        }
        sep();
        {
        // what is the next business day?
        BigDate bigDate = BigDate.localToday();
        int interval;
        switch ( bigDate.getDayOfWeek() )
            {
            case 5/* Friday -> Monday */:
                interval = 3;
                break;

            case 6/* Saturday -> Monday */:
                interval = 2;
                break;

            case 0/* Sunday -> Monday */:
            case 1/* Monday -> Tuesday */:
            case 2/* Tuesday -> Wednesday */:
            case 3/* Wednesday -> Thursday */:
            case 4/* Thursday -> Friday */:
            default:
                interval = 1;
                break;
            }// end switch
        bigDate.addDays( interval );
        System.out.println( "Next business day = " + bigDate.toString() + "." );
        }
        sep();
        {
        // What Day of the Month Is The Second Thursday Of This Month?
        // This is when the Vancouver PC User Society (VPCUS) meets.
        // MacMillan planetarium.
        BigDate today = BigDate.localToday();
        int dayOfMonthOfSecondThursday = BigDate.nthXXXDay( 2
                /* second */,
                BigDate.THURSDAY,
                today.getYYYY(),
                today
                        .getMM() );
        System.out
                .println(
                        "VPCUS meets the second Thursday of the month. This month's meeting is on the "
                        + dayOfMonthOfSecondThursday
                        + "th." );
        }
        sep();
        {
        // What Day of the Month Is The third Thursday Of This Month?
        // This is when the Vancouver Apple User Society meets.
        // Scottish Cultural Center, 8886 Hudson, near the Oak St Bridge
        BigDate today = BigDate.localToday();
        int dayOfMonthOfThirdThursday = BigDate.nthXXXDay( 3
                /* third */,
                BigDate.THURSDAY,
                today.getYYYY(),
                today.getMM() );

        System.out
                .println(
                        "Apples BC meets the third Thursday of the month. This month's meeting is on the "
                        + dayOfMonthOfThirdThursday
                        + "th." );
        }
        sep();
        {
        // When is the next issue of Xtra West magazine due out
        // It came out 2000-07-27, and comes out every two weeks.
        BigDate today = BigDate.localToday();
        BigDate first = new BigDate( 2000, 7, 27 );
        int days = today.getOrdinal() - first.getOrdinal();
        int fortnights = ( days + 13 ) / 14;// round up
        BigDate next = new BigDate( first.getOrdinal() + fortnights * 14 );
        System.out
                .println( "Next issue of Xtra West magazine is due out "
                          + next.toString()
                          + "." );
        }
        sep();
        {
        // When is J. McRee (Mac) Elrod's next potluck?
        // http://www.islandnet.com/~jelrod/gpl.html
        // the fourth Saturday of the month, jan, apr, jul, oct, every 3
        // months.
        BigDate today = BigDate.localToday();
        int year = today.getYYYY();
        // 1>1 2>4 3>4 4>4 5>7 6>7 7>7 8>10 9>10 10>10 11>1 12>1
        int month = ( ( ( today.getMM() + ( 3 - 1 - 1 ) ) / 3 ) * 3 ) % 12 + 1;
        BigDate when = new BigDate( BigDate.ordinalOfnthXXXDay( 4/* fourth */,
                BigDate.SATURDAY,
                year,
                month ) );
        if ( when.getOrdinal() < today.getOrdinal() )
            {
            // we missed this month's potlock, get next one.
            month += 3;
            if ( month > 12 )
                {
                year++;
                month -= 12;
                when = new BigDate( BigDate.ordinalOfnthXXXDay( 4/* fourth */,
                        BigDate.SATURDAY,
                        year,
                        month ) );
                }
            }
        System.out
                .println(
                        "Mac's next potluck in on the fourth Saturday of the month, every 3 months,\nNext is on "
                        + when );
        }
        sep();
        {
        // What Day of the Month Is The Last Friday Of This Month?
        BigDate today = BigDate.localToday();
        int dayOfMonthOfLastFriday = BigDate.nthXXXDay( 5
                /* last */,
                BigDate.FRIDAY,
                today.getYYYY(),
                today.getMM() );

        System.out
                .println( "The last Friday of the month is on the "
                          + dayOfMonthOfLastFriday
                          + "th." );
        }
        sep();

        {
        // Precisely how old is Roedy Green, in years, months and days
        // Roedy was born on February 4, 1948.
        BigDate birthDate = new BigDate( 1948, 2, 4 );
        BigDate today = BigDate.localToday();
        int[] age = BigDate.age( birthDate, today );
        System.out
                .println( "Today Roedy is "
                          + age[ 0 ]
                          + " years and "
                          + age[ 1 ]
                          + " months and "
                          + age[ 2 ]
                          + " days old." );
        System.out
                .println( "or "
                          + ( today.getOrdinal() - birthDate.getOrdinal() )
                          + " days." );
        }
        sep();
        {
        // How many days old was C Green on her 53th birthday
        // She was born on  was born on May 31, 1955.48.
        BigDate birthDate = new BigDate( 1955, 5, 31 );
        BigDate fiftythird = new BigDate( 2008, 5, 31 );
        System.out.println( "C. Green was "
                            + ( fiftythird.getOrdinal() - birthDate.getOrdinal() )
                            + " days old on her 53rd birthday." );
        }
        sep();

        {
        // Precisely how old is John McCain, in years, months and days
        // John McCain was born on 1936-08-29.
        BigDate birthDate = new BigDate( 1936, 8, 28 );
        BigDate today = BigDate.localToday();
        int[] age = BigDate.age( birthDate, today );
        System.out.println( "John McCain was born on " + birthDate.toString() + "." );
        System.out
                .println( "Today John McCain is "
                          + age[ 0 ]
                          + " years and "
                          + age[ 1 ]
                          + " months and "
                          + age[ 2 ]
                          + " days old." );
        System.out
                .println( "or "
                          + ( today.getOrdinal() - birthDate.getOrdinal() )
                          + " days." );

        BigDate inaug1 = new BigDate( 2009, 1, 20 );
        age = BigDate.age( birthDate, inaug1 );
        System.out
                .println( "John McCain would be "
                          + age[ 0 ]
                          + " years and "
                          + age[ 1 ]
                          + " months and "
                          + age[ 2 ]
                          + " days old when he first takes office" );

        BigDate inaug2 = new BigDate( 2013, 1, 21 );
        age = BigDate.age( birthDate, inaug2 );
        System.out
                .println( "John McCain would be "
                          + age[ 0 ]
                          + " years and "
                          + age[ 1 ]
                          + " months and "
                          + age[ 2 ]
                          + " days old when he starts his second term." );

        BigDate leave = new BigDate( 2017, 1, 20 - 1 );
        age = BigDate.age( birthDate, leave );
        System.out
                .println( "John McCain would be "
                          + age[ 0 ]
                          + " years and "
                          + age[ 1 ]
                          + " months and "
                          + age[ 2 ]
                          + " days old when he leaves office." );
        }
        sep();

        {
        // How old would John Lennon be, in years, months and days
        // Lennon was born on October 9, 1940.
        BigDate birthDate = new BigDate( 1940, 10, 9 );
        BigDate today = BigDate.localToday();
        int[] age = BigDate.age( birthDate, today );
        System.out
                .println( "Today John Lennon would be "
                          + age[ 0 ]
                          + " years and "
                          + age[ 1 ]
                          + " months and "
                          + age[ 2 ]
                          + " days old." );
        }
        sep();
        {
        // How long since John Lennon died, in years, months and days
        // Lennon was born on December 8, 1980.
        BigDate deathDate = new BigDate( 1980, 12, 8 );
        BigDate today = BigDate.localToday();
        int[] age = BigDate.age( deathDate, today );
        System.out
                .println( "It has been "
                          + age[ 0 ]
                          + " years and "
                          + age[ 1 ]
                          + " months and "
                          + age[ 2 ]
                          + " days since John Lennon was murdered." );
        }
        sep();
        {
        // How old will Little Richard be on his next birthday?

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -