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 Calendar dateShortBrToCalendar(String data) throws ParseException {
    SimpleDateFormat sdf = new SimpleDateFormat("MMM/yyyy", Locale.getDefault());
    Date date = sdf.parse(data);// w  ww. j a v  a2 s  .c  o m
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    return calendar;
}

From source file:Main.java

public static final Calendar getCurrentCalendar(Date date) {
    Calendar result = getCurrentCalendar();
    result.setTime(date);
    return result;
}

From source file:Main.java

public static boolean isTheSameDay(Date one, Date another) {
    Calendar _one = Calendar.getInstance();
    _one.setTime(one);
    Calendar _another = Calendar.getInstance();
    _another.setTime(another);/*from   www  .  ja  v a2s  . co m*/
    int oneDay = _one.get(Calendar.DAY_OF_YEAR);
    int anotherDay = _another.get(Calendar.DAY_OF_YEAR);

    return oneDay == anotherDay;
}

From source file:Main.java

/**
 * Converts Date into XML-Tag with type xsd:dateTime
 *//*from   w  ww.  j av a  2s .  c om*/
public static String getXMLDate(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    return DatatypeConverter.printDateTime(calendar);
}

From source file:Main.java

public static Date getLastWeekOfYear(Date date) {
    // Set time/*from w  ww.ja  v a  2  s.c o  m*/
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    // Go to last week
    calendar.add(Calendar.WEEK_OF_YEAR, -1);
    return calendar.getTime();
}

From source file:Main.java

public static String getYearStringFromDate(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);

    StringBuilder sb = new StringBuilder("Year ").append(calendar.get(Calendar.YEAR));

    return sb.toString();
}

From source file:Main.java

public static Calendar dateUSToCalendar(String data) throws ParseException {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
    Date date = sdf.parse(data);//from   www.j av  a2 s .  c o  m
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    return calendar;
}

From source file:Main.java

public static int getUpMonthDays(Date date) {
    Calendar c = Calendar.getInstance();
    c.setTime(date);
    c.add(Calendar.MONTH, -1);/*from  w  ww . j a va  2  s  . co m*/
    return c.getActualMaximum(Calendar.DAY_OF_MONTH);
}

From source file:Main.java

public static Date add(Date date, int field, int amount) {
    Calendar c = Calendar.getInstance();
    c.setTime(date);
    c.add(field, amount);/*ww w .  j  a v  a  2s.  c  om*/
    return c.getTime();
}

From source file:Main.java

public static Date getEndOfDate(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    calendar.set(Calendar.HOUR, 23);
    calendar.set(Calendar.MINUTE, 59);
    calendar.set(Calendar.SECOND, 59);
    return calendar.getTime();
}