Example usage for java.util GregorianCalendar get

List of usage examples for java.util GregorianCalendar get

Introduction

In this page you can find the example usage for java.util GregorianCalendar get.

Prototype

public int get(int field) 

Source Link

Document

Returns the value of the given calendar field.

Usage

From source file:PVGraph.java

public static void main(String[] args) {
    loadProperties();/*from   www  .j a v  a  2s.c o m*/
    try {
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        getDatabaseConnection();
    } catch (SQLException e) {
        System.err.println("Cannot establish database connection: " + e.getMessage());
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
    if (conn != null) {
        // create first window
        new PVGraph();
        int smatoolPeriod = Integer.decode(props.getProperty("smatool.period", "0"));
        while (smatoolPeriod > 0) {
            loadProperties();
            smatoolPeriod = Integer.decode(props.getProperty("smatool.period", "0"));
            int smatoolStartHour = Integer.decode(props.getProperty("smatool.starthour", "0"));
            int smatoolEndHour = Integer.decode(props.getProperty("smatool.endhour", "24"));
            GregorianCalendar now = new GregorianCalendar();
            int nowHour = now.get(Calendar.HOUR_OF_DAY);
            if (nowHour >= smatoolStartHour && nowHour < smatoolEndHour) {
                try {
                    runSmatool();
                    synchronized (graphs) {
                        for (PVGraph g : graphs)
                            g.updateView();
                    }
                } catch (IOException ioe) {
                    System.err.println(ioe.getMessage());
                }
            }
            try {
                Thread.sleep(smatoolPeriod * 60 * 1000);
            } catch (InterruptedException ie) {
                // break;
            }
        }
    }
}

From source file:Main.java

public static byte[] calendarToBytes(GregorianCalendar cal) {
    return new byte[] { (byte) (cal.get(GregorianCalendar.YEAR) - 2000),
            (byte) cal.get(GregorianCalendar.MONTH), (byte) cal.get(GregorianCalendar.DAY_OF_MONTH),
            (byte) cal.get(GregorianCalendar.HOUR_OF_DAY), (byte) cal.get(GregorianCalendar.MINUTE),
            (byte) cal.get(GregorianCalendar.SECOND) };
}

From source file:Main.java

public static float getTime() {
    GregorianCalendar now = new GregorianCalendar();
    float x = now.get(GregorianCalendar.HOUR_OF_DAY);
    float y = now.get(GregorianCalendar.MINUTE);
    y = y / 100;//from w ww  .  ja v a  2s.  c  o  m
    x = x + y;
    return x;
}

From source file:Main.java

public static int dayOfWeek() {
    GregorianCalendar g = new GregorianCalendar();
    int ret = g.get(java.util.Calendar.DAY_OF_WEEK);
    g = null;/*w  w w .  j av a2 s .c  o m*/
    return ret;
}

From source file:DateUtils.java

public static Date getLastWeek() {
    GregorianCalendar dayBeforeThisWeek = new GregorianCalendar();
    int dayFromMonday = (dayBeforeThisWeek.get(Calendar.DAY_OF_WEEK) + 7 - Calendar.MONDAY) % 7;
    dayBeforeThisWeek.add(Calendar.DATE, -dayFromMonday - 1);
    return dayBeforeThisWeek.getTime();
}

From source file:Main.java

public static float getPercentOfDay() {
    GregorianCalendar cal = new GregorianCalendar();
    float dayMillis = 0;
    dayMillis += (cal.get(Calendar.HOUR_OF_DAY) * 60 * 60);
    dayMillis += (cal.get(Calendar.MINUTE) * 60);
    dayMillis += cal.get(Calendar.SECOND);
    float totalDayMillis = (24f * 60f * 60f);
    return (dayMillis / totalDayMillis);
}

From source file:Main.java

public static int getYears(int year, int month, int day) {

    GregorianCalendar cal = new GregorianCalendar();
    int y, m, d, noofyears;

    y = cal.get(Calendar.YEAR);// current year ,
    m = cal.get(Calendar.MONTH);// current month 
    d = cal.get(Calendar.DAY_OF_MONTH);//current day
    cal.set(year, month, day);// here ur date 
    noofyears = y - cal.get(Calendar.YEAR);
    if ((m < cal.get(Calendar.MONTH))
            || ((m == cal.get(Calendar.MONTH)) && (d < cal.get(Calendar.DAY_OF_MONTH)))) {
        --noofyears;/*ww w .  ja v  a2  s  .  c  o  m*/
    }
    try {
        if (noofyears < 0)
            throw new IllegalArgumentException("age < 0");
    } catch (IllegalArgumentException ile) {
        ile.printStackTrace();
    }
    System.out.println(noofyears);
    return noofyears;
}

From source file:Main.java

public static long currentMonthInMills() {
    GregorianCalendar gregoriancalendar = new GregorianCalendar();
    GregorianCalendar gregoriancalendar1 = new GregorianCalendar(gregoriancalendar.get(1),
            gregoriancalendar.get(2), 1);
    gregoriancalendar1.setTimeZone(GMT);
    return gregoriancalendar1.getTimeInMillis();
}

From source file:Main.java

/**
 * Calculates the difference in days, rounding the operands down to the nearest day.
 * Ex. Jan 3rd 12:31 pm - Jan 2nd 4:00 pm
 * =   Jan 3rd - Jan 2nd//from ww  w .  j ava  2s .  c o m
 * =   1 day 
 * @return The difference in days.
 */
public static int differenceInDays(GregorianCalendar minuend, GregorianCalendar subtrahend) {
    GregorianCalendar minuendFloor = new GregorianCalendar(minuend.get(Calendar.YEAR),
            minuend.get(Calendar.MONTH), minuend.get(Calendar.DAY_OF_MONTH));
    GregorianCalendar subtrahendFloor = new GregorianCalendar(subtrahend.get(Calendar.YEAR),
            subtrahend.get(Calendar.MONTH), subtrahend.get(Calendar.DAY_OF_MONTH));
    GregorianCalendar result = new GregorianCalendar();
    result.setTimeInMillis(minuendFloor.getTimeInMillis() - subtrahendFloor.getTimeInMillis());
    return result.get(Calendar.DAY_OF_YEAR);
}

From source file:Main.java

public static long currentWeekInMills() {
    GregorianCalendar gregoriancalendar = new GregorianCalendar();
    GregorianCalendar gregoriancalendar1 = new GregorianCalendar(gregoriancalendar.get(1),
            gregoriancalendar.get(2), gregoriancalendar.get(5));
    gregoriancalendar1.setTimeZone(GMT);
    gregoriancalendar1.add(6, -(gregoriancalendar.get(7) - gregoriancalendar.getFirstDayOfWeek()));
    return gregoriancalendar1.getTimeInMillis();
}