Package hirondelle.date4j

Examples of hirondelle.date4j.DateTime$MissingItem


    /**
     * What is the current date-time in the JRE's default time zone?
     */
    public static void currentDateTime () {
        DateTime now = DateTime.now( TimeZone.getDefault() );
        String result = now.format( "YYYY-MM-DD hh:mm:ss" );
        log( "Current date-time in default time zone : " + result );
    }
View Full Code Here


    /**
     * What is the current date-time in Cairo (include weekday)?
     */
    public static void currentDateTimeInCairo () {
        DateTime now = DateTime.now( TimeZone.getTimeZone( "Africa/Cairo" ) );
        String result = now.format( "YYYY-MM-DD hh:mm:ss (WWWW)", Locale.getDefault() );
        log( "Current date-time in Cairo : " + result );
    }
View Full Code Here

    /**
     * What's the age of someone born May 16, 1995?
     */
    public static void ageIfBornOnCertainDate () {
        DateTime today = DateTime.today( TimeZone.getDefault() );
        DateTime birthdate = DateTime.forDateOnly( 1995, 5, 16 );
        int age = today.getYear() - birthdate.getYear();
        if ( today.getDayOfYear() < birthdate.getDayOfYear() ) {
            age = age - 1;
        }
        log( "Age of someone born May 16, 1995 is : " + age );
    }
View Full Code Here

    /**
     * Stock options expire on the 3rd Friday of this month. What day of the month is that?
     */
    public static void optionsExpiry () {
        DateTime today = DateTime.today( TimeZone.getDefault() );
        DateTime firstOfMonth = today.getStartOfMonth();
        int result = 0;
        if ( firstOfMonth.getWeekDay() == 7 ) {
            result = 21;
        } else {
            result = 21 - firstOfMonth.getWeekDay();
        }
        DateTime thirdFriday = DateTime.forDateOnly( firstOfMonth.getYear(), firstOfMonth.getMonth(), result );
        log( "The 3rd Friday of this month is : " + thirdFriday.format( "YYYY-MM-DD" ) );
    }
View Full Code Here

    /**
     * How many days till the next December 25?
     */
    public static void daysTillChristmas () {
        DateTime today = DateTime.today( TimeZone.getDefault() );
        DateTime christmas = DateTime.forDateOnly( today.getYear(), 12, 25 );
        int result = 0;
        if ( today.isSameDayAs( christmas ) ) {
            // do nothing
        } else if ( today.lt( christmas ) ) {
            result = today.numDaysFrom( christmas );
        } else if ( today.gt( christmas ) ) {
            DateTime christmasNextYear = DateTime.forDateOnly( today.getYear() + 1, 12, 25 );
            result = today.numDaysFrom( christmasNextYear );
        }
        log( "Number of days till Christmas : " + result );
    }
View Full Code Here

    /**
     * What day is 90 days from today?
     */
    public static void whenIs90DaysFromToday () {
        DateTime today = DateTime.today( TimeZone.getDefault() );
        log( "90 days from today is : " + today.plusDays( 90 ).format( "YYYY-MM-DD" ) );
    }
View Full Code Here

    /**
     * What day is 3 months and 5 days from today?
     */
    public static void whenIs3Months5DaysFromToday () {
        DateTime today = DateTime.today( TimeZone.getDefault() );
        DateTime result = today.plus( 0, 3, 5, 0, 0, 0, 0, DateTime.DayOverflow.FirstDay );
        log( "3 months and 5 days from today is : " + result.format( "YYYY-MM-DD" ) );
    }
View Full Code Here

    /**
     * Current number of hours difference between Paris, France and Perth, Australia.
     */
    public static void hoursDifferenceBetweenParisAndPerth () {
        //this assumes the time diff is a whole number of hours; other styles are possible
        DateTime paris = DateTime.now( TimeZone.getTimeZone( "Europe/Paris" ) );
        DateTime perth = DateTime.now( TimeZone.getTimeZone( "Australia/Perth" ) );
        int result = perth.getHour() - paris.getHour();
        if ( result < 0 ) {
            result = result + 24;
        }
        log( "Numbers of hours difference between Paris and Perth : " + result );
    }
View Full Code Here

    /**
     * How many weeks is it since Sep 6, 2010?
     */
    public static void weeksSinceStart () {
        DateTime today = DateTime.today( TimeZone.getDefault() );
        DateTime startOfProject = DateTime.forDateOnly( 2010, 9, 6 );
        int result = today.getWeekIndex() - startOfProject.getWeekIndex();
        log( "The number of weeks since Sep 6, 2010 : " + result );
    }
View Full Code Here

    /**
     * How much time till midnight?
     */
    public static void timeTillMidnight () {
        DateTime now = DateTime.now( TimeZone.getDefault() );
        DateTime midnight = now.plusDays( 1 ).getStartOfDay();
        long result = now.numSecondsFrom( midnight );
        log( "This many seconds till midnight : " + result );
    }
View Full Code Here

TOP

Related Classes of hirondelle.date4j.DateTime$MissingItem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.