Example usage for java.util Calendar setTime

List of usage examples for java.util Calendar setTime

Introduction

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

Prototype

public final void setTime(Date date) 

Source Link

Document

Sets this Calendar's time with the given Date.

Usage

From source file:Main.java

public static int getWeekOfDate(Date dt) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(dt);
    int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
    return w < 0 ? 0 : w;
}

From source file:Main.java

public static int getDayOfMonth(Date date) {
    Calendar c = Calendar.getInstance();
    c.setTime(date);
    return c.get(Calendar.DAY_OF_MONTH);
}

From source file:Main.java

public static String convertTime(int fetchDate, SimpleDateFormat sdf) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date((long) fetchDate * 1000));
    return sdf.format(cal.getTime());
}

From source file:Main.java

public static int getMonth(Date date) {
    Calendar c = Calendar.getInstance();
    c.setTime(date);
    return c.get(Calendar.MONTH);
}

From source file:Main.java

public static int getTheMonthDayCount(Date date) {
    Calendar c = Calendar.getInstance();
    c.setTime(date);
    int lastDay = c.getActualMaximum(Calendar.DAY_OF_MONTH);

    return lastDay;
}

From source file:Main.java

public static Date addTimeInterval(Date origin, int value, int unit) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(origin);
    cal.add(unit, value);//from w  w  w  .j  ava2s  .  c o m
    return cal.getTime();
}

From source file:Main.java

public static int getDayOfYear(Date date) {
    Calendar c = Calendar.getInstance();
    c.setTime(date);
    return c.get(Calendar.DAY_OF_YEAR);
}

From source file:Main.java

public static Date getDateAfter(Date d, int day) {
    Calendar now = Calendar.getInstance();
    now.setTime(d);
    now.set(Calendar.DATE, now.get(Calendar.DATE) + day);
    return now.getTime();
}

From source file:Main.java

private static Calendar date2calendar(Date date) {
    Calendar tmpCale = Calendar.getInstance();
    tmpCale.setTime(date);
    return tmpCale;
}

From source file:Main.java

public static Long getIncTimeInMillis(Date originDate, int increment) {
    if (null == originDate)
        return null;
    Calendar c = Calendar.getInstance();
    c.setTime(originDate);
    c.add(Calendar.MINUTE, increment);
    return c.getTimeInMillis();
}