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 final int getMonthByMill(long mill) {
    Date curDate = new Date(mill);
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(curDate);
    return calendar.get(java.util.Calendar.MONTH) + 1;
}

From source file:Main.java

public static Date offsiteDate(Date date, int calendarField, int offsite) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    cal.add(calendarField, offsite);/*from   w  w w .  jav a  2  s.com*/
    return cal.getTime();
}

From source file:Main.java

public static final int getYearByMill(long mill) {
    Date curDate = new Date(mill);
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(curDate);
    return calendar.get(java.util.Calendar.YEAR);
}

From source file:Main.java

public static final int getDayByMill(long mill) {
    Date curDate = new Date(mill);
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(curDate);
    return calendar.get(java.util.Calendar.DAY_OF_MONTH);
}

From source file:Main.java

public static int getTotalWeeks(Date date) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    return getTotalWeeks(cal);
}

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;
    if (w < 0)
        w = 0;//from  www  .ja  v  a2s .  c om
    return w;
}

From source file:Main.java

public static Date plusHours(Date date, int n) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    calendar.add(Calendar.HOUR_OF_DAY, n);
    return calendar.getTime();
}

From source file:Main.java

public static int getDiffOfYears(Date starDate, Date endDate) {
    Calendar star = Calendar.getInstance();
    star.setTime(starDate);
    Calendar end = Calendar.getInstance();
    end.setTime(endDate);/*w  w  w . j  a  v  a2 s .co m*/
    int diffYear = star.get(Calendar.YEAR) - end.get(Calendar.YEAR);
    return Math.abs(diffYear);
}

From source file:Main.java

public static Date getStartOfMonth(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    calendar.set(Calendar.DATE, 1);
    return calendar.getTime();
}

From source file:Main.java

public static Calendar getCurrentDate() {
    Calendar currentDate = Calendar.getInstance();
    currentDate.setTime(new Date());
    return currentDate;
}