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:com.fluke.util.Util.java

public static String addDate(Date date, int noOfDays) {
    Calendar c = Calendar.getInstance();
    c.setTime(date);
    c.add(Calendar.DATE, noOfDays); // Adding 5 days
    return getDate(c.getTime());

}

From source file:info.magnolia.cms.util.DateUtil.java

/**
 * Get the equivalent UTC calendar to a local calendar
 *///w  w w . ja  va2 s .com
public static Calendar getLocalCalendarFromUTC(Calendar utc) {
    Date valueDate = utc.getTime();
    Calendar c = Calendar.getInstance(); // this has the default timezone for the server
    c.setTime(valueDate);
    return c;
}

From source file:net.ceos.project.poi.annotated.bean.PropagationHorizontalObjectBuilder.java

/**
 * Validate the PropagationHorizontalObject based on the object build with the method
 * 'buildPropagationHorizontalObject'/*from  w w w  . j  a  v a2 s  .c  o m*/
 * 
 * @param toValidate
 *            the object to validate
 */
public static void validatePropagationHorizontalObject(PropagationHorizontalObject toValidate) {
    PropagationHorizontalObject base = buildPropagationHorizontalObject();

    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());

    Calendar calendarUnmarshal = Calendar.getInstance();
    calendarUnmarshal.setTime(toValidate.getDateAttribute());
    assertEquals(calendar.get(Calendar.YEAR), calendarUnmarshal.get(Calendar.YEAR));
    assertEquals(calendar.get(Calendar.MONTH), calendarUnmarshal.get(Calendar.MONTH));
    assertEquals(calendar.get(Calendar.DAY_OF_MONTH), calendarUnmarshal.get(Calendar.DAY_OF_MONTH));
    assertEquals(base.getStringAttribute(), toValidate.getStringAttribute());
    assertEquals(base.getIntegerAttribute(), toValidate.getIntegerAttribute());
    assertEquals(base.getBooleanAttribute(), toValidate.getBooleanAttribute());
    assertEquals(base.getDoublePrimitiveAttribute(), toValidate.getDoublePrimitiveAttribute());
    assertEquals(base.getLongPrimitiveAttribute(), toValidate.getLongPrimitiveAttribute());
    assertEquals(base.getFloatAttribute(), toValidate.getFloatAttribute());
    assertEquals(base.getUnitFamily(), toValidate.getUnitFamily());
    assertEquals(base.getBigDecimalAttribute(), toValidate.getBigDecimalAttribute());
    // TODO add new validation below
}

From source file:Main.java

public static String getMonth(final Date date) {
    if (date != null) {
        Calendar calendar = Calendar.getInstance();
        TimeZone timeZone = TimeZone.getTimeZone("GMT+8");
        calendar.setTimeZone(timeZone);/*from  ww w . j  a va  2 s  .co m*/
        calendar.setTime(date);
        return String.valueOf(calendar.get(Calendar.MONTH) + 1);
    }
    return "0";
}

From source file:it.unicaradio.android.models.Transmission.java

private static String adjustTime(String time) {
    SimpleDateFormat formatter = new SimpleDateFormat("HH:mm");
    String adjustedTime = time;/*from  ww w  .  ja  va2 s. co  m*/
    try {
        Date date = formatter.parse(time);
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.HOUR_OF_DAY, 1);
        adjustedTime = formatter.format(cal.getTime());
    } catch (ParseException e) {
    }

    return adjustedTime;
}

From source file:net.ceos.project.poi.annotated.bean.ConditionalFormatObjectBuilder.java

/**
 * Validate the ConditionalFormatObject based on the object build with the method
 * 'buildConditionalFormatObject'/*from   w  ww .ja v a2  s  . c  o m*/
 * 
 * @param toValidate
 *            the object to validate
 */
public static void validateConditionalFormatObject(ConditionalFormatObject toValidate) {
    ConditionalFormatObject base = buildConditionalFormatObject();

    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());

    Calendar calendarUnmarshal = Calendar.getInstance();
    calendarUnmarshal.setTime(toValidate.getDateAttribute());
    assertEquals(calendar.get(Calendar.YEAR), calendarUnmarshal.get(Calendar.YEAR));
    assertEquals(calendar.get(Calendar.MONTH), calendarUnmarshal.get(Calendar.MONTH));
    assertEquals(calendar.get(Calendar.DAY_OF_MONTH), calendarUnmarshal.get(Calendar.DAY_OF_MONTH));

    assertEquals(base.getStringAttribute(), toValidate.getStringAttribute());
    assertEquals(base.getIntegerAttribute(), toValidate.getIntegerAttribute());
    assertEquals(base.getDoubleAttribute(), toValidate.getDoubleAttribute());
    assertEquals(base.getLongAttribute(), toValidate.getLongAttribute());
    assertEquals(base.getBooleanAttribute(), toValidate.getBooleanAttribute());
    assertEquals(base.getJob().getJobCode(), toValidate.getJob().getJobCode());
    assertEquals(base.getJob().getJobFamily(), toValidate.getJob().getJobFamily());
    assertEquals(base.getJob().getJobName(), toValidate.getJob().getJobName());
}

From source file:Main.java

public static Calendar StringToCalendar(String datetime) {
    Calendar calendar = Calendar.getInstance();
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    try {//from ww w  .j  a va2s .  c o  m
        calendar.setTime(simpleDateFormat.parse(datetime));
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return calendar;
}

From source file:com.acmeair.loader.FlightLoader.java

private static Date getArrivalTime(Date departureTime, int mileage) {
    double averageSpeed = 600.0; // 600 miles/hours
    double hours = (double) mileage / averageSpeed; // miles / miles/hour = hours
    double partsOfHour = hours % 1.0;
    int minutes = (int) (60.0 * partsOfHour);
    Calendar c = Calendar.getInstance();
    c.setTime(departureTime);
    c.add(Calendar.HOUR, (int) hours);
    c.add(Calendar.MINUTE, minutes);
    return c.getTime();
}

From source file:com.tinypace.mobistore.util.DateUtils.java

/** 
  * ? //from   www .  j  av  a  2  s.  co m
  *  
  * @param d 
  * @param day 
  * @return 
  */
public static Date getDateBefore(Date d, int day) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(d);
    cal.set(Calendar.DATE, cal.get(Calendar.DATE) - day);
    return cal.getTime();
}

From source file:com.tinypace.mobistore.util.DateUtils.java

/** 
 * ? //from w w  w.  j  ava  2s  .  co m
 *  
 * @param d 
 * @param day
 * @return 
 */
public static Date getDateAfter(Date d, int day) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(d);
    cal.set(Calendar.DATE, cal.get(Calendar.DATE) + day);
    return cal.getTime();
}