Example usage for java.util Calendar DATE

List of usage examples for java.util Calendar DATE

Introduction

In this page you can find the example usage for java.util Calendar DATE.

Prototype

int DATE

To view the source code for java.util Calendar DATE.

Click Source Link

Document

Field number for get and set indicating the day of the month.

Usage

From source file:com.saax.gestorweb.util.DAOAleatorio.java

public static Date getDataByOffset(int offsetDataAtual, boolean up) {
    GregorianCalendar gc = new GregorianCalendar();
    Date hoje = DateUtils.truncate(new Date(), Calendar.DATE);
    gc.setTime(hoje); // hoje truncando as horas

    for (int i = 0; i < offsetDataAtual; i++) {
        gc.roll(GregorianCalendar.DAY_OF_MONTH, up);
        if (gc.getActualMaximum(GregorianCalendar.DAY_OF_MONTH) == gc.get(GregorianCalendar.DAY_OF_MONTH)) {
            gc.roll(GregorianCalendar.MONTH, up);

        }/* ww w  .j  a va2  s . com*/
    }
    return DateUtils.truncate(new Date(gc.getTimeInMillis()), Calendar.DATE);

}

From source file:Main.java

public Date next() {
    current.add(Calendar.DATE, 1);
    return current.getTime();
}

From source file:fitness.datagrapgh.java

public datagrapgh(String table, String y) throws SQLException {
    frame = new JFrame();
    Calendar cal = Calendar.getInstance();
    DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
    cal.add(Calendar.DATE, -8);
    XYSeriesCollection dataset = new XYSeriesCollection();
    XYSeries series1 = new XYSeries(table);
    connec c = new connec();
    for (int i = 0; i < 7; i++) {
        cal.add(Calendar.DATE, 1);
        String s = df.format(cal.getTime());
        c.connect();/*from w w  w.  j  a va2  s. c  o m*/
        if (table.equals("consumption")) {
            c.rs = c.st.executeQuery(
                    "SELECT calories FROM consumption WHERE uid='" + temp.getId() + "' AND date='" + s + "'");
            while (c.rs.next()) {
                //System.out.println("hello");
                String gra = c.rs.getString("calories");
                int n = Integer.parseInt(gra);
                series1.add(i, n);
            }
        } else {
            c.rs = c.st.executeQuery("SELECT calories_burned FROM workout WHERE uid='" + temp.getId()
                    + "' AND date='" + s + "'");
            while (c.rs.next()) {
                //System.out.println("hello");
                String gra = c.rs.getString("calories_burned");
                int n = Integer.parseInt(gra);
                series1.add(i, n);
            }
        }

    }
    c.disconnect();
    dataset.addSeries(series1);
    JFreeChart chart = ChartFactory.createXYLineChart("Fitness analyisis", "day", y, dataset,
            PlotOrientation.VERTICAL, true, true, false);
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(400, 400));
    chartPanel.setBounds(100, 100, 400, 400);
    chartPanel.setVisible(true);
    frame.setSize(500, 500);
    frame.setVisible(true);
    frame.add(chartPanel);

}

From source file:com.jennifer.ui.util.TimeUtil.java

public static Date add(Date d, String type, int interval) {
    Calendar c = Calendar.getInstance();
    c.setTime(d);/*  w  ww .java  2  s  . c o  m*/

    if (Time.YEARS.equals(type)) {
        c.add(Calendar.YEAR, interval);
    } else if (Time.MONTHS.equals(type)) {
        c.add(Calendar.MONTH, interval);
    } else if (Time.DAYS.equals(type)) {
        c.add(Calendar.DATE, interval);
    } else if (Time.HOURS.equals(type)) {
        c.add(Calendar.HOUR_OF_DAY, interval);
    } else if (Time.MINUTES.equals(type)) {
        c.add(Calendar.MINUTE, interval);
    } else if (Time.SECONDS.equals(type)) {
        c.add(Calendar.SECOND, interval);
    } else if (Time.MILLISECONDS.equals(type)) {
        c.add(Calendar.MILLISECOND, interval);
    } else if (Time.WEEKS.equals(type)) {
        c.add(Calendar.DATE, interval * 7);
    }

    return c.getTime();
}

From source file:net.kamhon.ieagle.util.DateUtil.java

public static Date getStartDateOfWeek(Date date) {
    Calendar calendarStartDate = DateUtil.setTime(date);
    Integer noOfDayOfWeek = calendarStartDate.get(Calendar.DAY_OF_WEEK) - 1;
    calendarStartDate.add(Calendar.DATE, -noOfDayOfWeek);

    return calendarStartDate.getTime();
}

From source file:com.example.mediastock.util.Utilities.java

/**
 * Method to get the date./*w w  w  .  ja  v a2s. c  o  m*/
 *
 * @param day the day of a certain day
 * @return a date string
 */
public static String getDate(int day) {
    SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DATE, -day);

    Date d = calendar.getTime();

    return ft.format(d);
}

From source file:Main.java

public void paintComponent(Graphics g) {
    ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g.fillRect(0, 0, getWidth(), getHeight());
    g.setColor(Color.black);/*from   w w  w. ja  v  a 2s.  c  om*/
    g.drawString(month.format(date), 34, 36);
    g.setColor(Color.white);
    g.drawString(year.format(date), 235, 36);

    Calendar today = Calendar.getInstance();
    today.setTime(date);
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    cal.set(Calendar.DATE, 1);
    cal.add(Calendar.DATE, -cal.get(Calendar.DAY_OF_WEEK) + 1);
    for (int week = 0; week < 6; week++) {
        for (int d = 0; d < 7; d++) {
            Color col = Color.black;
            g.drawString(day.format(cal.getTime()), d * 30 + 46 + 4, week * 29 + 81 + 20);
            cal.add(Calendar.DATE, +1);
        }
    }
}

From source file:io.lavagna.model.EventsCount.java

public EventsCount(@Column("EVENT_DATE") Date date, @Column("EVENT_COUNT") long count) {
    this.date = DateUtils.truncate(date, Calendar.DATE).getTime();
    this.count = count;
}

From source file:io.lavagna.model.StatisticsResult.java

public StatisticsResult(@Column("TIME") Date date,
        @Column("BOARD_COLUMN_DEFINITION_VALUE") ColumnDefinition columnDefinition,
        @Column("STATISTICS_COUNT") long count) {
    this.day = DateUtils.truncate(date, Calendar.DATE).getTime();
    this.columnDefinition = columnDefinition;
    this.count = count;
}

From source file:com.ykun.commons.utils.commons.DateUtils.java

/**
 * /*from   w  w  w .j a va  2 s .  co  m*/
 *
 * @param date
 * @param dayAmount
 * @return Date
 */
public static Date addDay(Date date, int dayAmount) {
    return addInteger(date, Calendar.DATE, dayAmount);
}