Example usage for java.util Calendar getTime

List of usage examples for java.util Calendar getTime

Introduction

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

Prototype

public final Date getTime() 

Source Link

Document

Returns a Date object representing this Calendar's time value (millisecond offset from the Epoch").

Usage

From source file:io.github.bluemarlin.util.BluemarlineUtil.java

public static Date getDateInThePast(int days) {
    Date dateNow = new Date();
    Calendar cal = Calendar.getInstance();
    cal.setTime(dateNow);//from ww w.  j a  v a 2 s. c o  m
    cal.add(Calendar.DATE, -days);
    Date d = cal.getTime();
    return d;
}

From source file:Main.java

public static boolean isToday(Calendar cal) {
    boolean ret = false;
    Calendar tmp = Calendar.getInstance();
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    String s1 = format.format(cal.getTime());
    String s2 = format.format(tmp.getTime());
    if (s1.equals(s2)) {
        ret = true;/*from www.  j  av a 2  s  .c om*/
    }
    return ret;
}

From source file:com.storageroomapp.client.util.StorageRoomUtil.java

/**
 * Serializes a Calendar as a StorageRoom time String
 * @param cal the Calendar//from  ww w.  j  a va  2 s.  c o m
 * @return the serialized String
 */
static public String calendarToStorageRoomTimeString(Calendar cal) {
    initFormatters();
    String date = timeFieldFormatter.format(cal.getTime());
    return date;
}

From source file:com.storageroomapp.client.util.StorageRoomUtil.java

/**
 * Serializes a Calendar as a StorageRoom date String
 * @param cal the Calendar/*from  ww w . j av a  2 s  .c  o  m*/
 * @return the serialized String
 */
static public String calendarToStorageRoomDateString(Calendar cal) {
    initFormatters();
    String date = dateFieldFormatter.format(cal.getTime());
    return date;
}

From source file:Main.java

private static void setStartOfWeekToCalendar(Calendar c) {
    c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek());
    setStartOfDayToCalendar(c);/*from w w w . ja va  2  s  . c  om*/
    Log.d("La Cuenta: ", "Min of Current Week: " + DateFormat.getInstance().format(c.getTime()));
}

From source file:Main.java

public static Date rewindToBeginningOfDay(Date date) {
    Calendar cal = buildFromDate(date);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);/*from  w w  w.j  av a2s  .  c  o  m*/
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTime();
}

From source file:Main.java

public static Date getStartOfDate(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);/*  w w w .ja  va  2  s  .  com*/
    calendar.set(Calendar.HOUR, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    return calendar.getTime();
}

From source file:net.duckling.ddl.util.Utility.java

public static String getDateCustom(Date date, String fmt) {
    Calendar calToday = Calendar.getInstance();
    calToday.set(Calendar.HOUR_OF_DAY, 0);
    Calendar calYear = Calendar.getInstance();
    calYear.set(Calendar.DAY_OF_YEAR, 1);
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);//from   w  w w  .  java2  s  .c o  m
    return (new SimpleDateFormat(fmt)).format(cal.getTime());
}

From source file:com.github.abhinavmishra14.aws.util.AWSUtil.java

/**
 * Gets the expiry date.<br/>/*w w  w  .  ja v  a2 s  . co  m*/
 * Expire by parameter takes input as Calendar.Month, Calendar.Hour, Calendar.Minute etc. 
 *
 * @param expireBy the expire by 
 * @param expireByValue the expire by value
 * @return the expiry date
 * @see Calendar
 */
public static Date getExpiryDate(final int expireBy, final int expireByValue) {
    final Date currentDate = new Date();
    final Calendar cal = Calendar.getInstance();
    cal.setTime(currentDate);
    cal.add(expireBy, expireByValue);
    return cal.getTime();
}