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:Main.java

public static Date getNextMonday(Date date) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);/*from w  ww  .  j  a  v  a2 s  . c  o m*/
    while (cal.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) {
        cal.add(Calendar.DAY_OF_WEEK, 1);
    }
    return cal.getTime();
}

From source file:Main.java

public static Date getNextSaturday(Date date) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);//w  ww.  j  a v a  2  s .com
    while (cal.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY) {
        cal.add(Calendar.DAY_OF_WEEK, 1);
    }
    return cal.getTime();
}

From source file:Main.java

public static String timestamp() {
    String timestamp = null;//from   w  ww. j  av a2 s. c o  m
    Calendar cal = Calendar.getInstance();
    DateFormat dfm = new SimpleDateFormat("yyyy-MM-ddHH:mm:ss", Locale.US);
    dfm.setTimeZone(TimeZone.getTimeZone("GMT"));
    timestamp = dfm.format(cal.getTime());
    return timestamp;
}

From source file:com.taobao.itest.util.DateConverter.java

public static Date getToday() {
    Calendar ca = Calendar.getInstance();
    return ca.getTime();
}

From source file:Main.java

public static Date getFetchDelayDate(Integer dateDelayMinutes) {
    Calendar c = Calendar.getInstance();
    if (dateDelayMinutes > 0) {
        dateDelayMinutes = -dateDelayMinutes;
    }/*from  w w w .  j ava2s .co  m*/
    c.add(Calendar.MINUTE, dateDelayMinutes);
    return c.getTime();
}

From source file:Main.java

public static String getFirstDayOfThisMonth() {
    String str = "";
    Calendar lastDate = Calendar.getInstance();
    lastDate.set(Calendar.DATE, 1);//
    // lastDate.add(Calendar.MONTH,-1);//
    // lastDate.add(Calendar.DATE,-1);//

    str = sdf.format(lastDate.getTime());
    return str;/*ww  w .  j  ava  2  s .  com*/
}

From source file:Main.java

public static boolean isInPast(int day, int month, int year) {
    Calendar c = Calendar.getInstance();

    c.set(Calendar.YEAR, year);/* www.j av a2  s.  c o m*/
    c.set(Calendar.MONTH, month - 1);
    c.set(Calendar.DAY_OF_MONTH, day);

    Date pastDate = c.getTime();

    return (pastDate.getTime() < new Date().getTime());
}

From source file:de.dominikschadow.duke.encounters.repositories.EncounterSpecification.java

public static Specification<Encounter> encounterAfterYear(int year) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, year);
    return (root, query, cb) -> cb.greaterThanOrEqualTo(root.<Date>get("date"), calendar.getTime());
}

From source file:it.geosolutions.opensdi2.mvc.SessionController.java

/** Transform Calendar to ISO 8601 string. */
public static String fromCalendar(final Calendar calendar) {
    Date date = calendar.getTime();
    String formatted = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(date);
    return formatted.substring(0, 22) + ":" + formatted.substring(22);
}

From source file:Util.java

/**
 * Unpacks date stored in kdb format.//  w w w  . ja  va  2 s .c o m
 * 
 * @param d
 * @return
 */
public static Date unpackDate(byte[] d) {
    // Byte bits: 00000000 11111111 22222222 33333333 44444444
    // Contents : 00YYYYYY YYYYYYMM MMDDDDDH HHHHMMMM MMSSSSSS
    int year = (d[0] << 6) | ((d[1] >> 2) & 0x0000003F);
    int month = ((d[1] & 0x00000003) << 2) | ((d[2] >> 6) & 0x00000003);
    int day = (d[2] >> 1) & 0x0000001F;
    int hour = ((d[2] & 0x00000001) << 4) | ((d[3] >> 4) & 0x0000000F);
    int minute = ((d[3] & 0x0000000F) << 2) | ((d[4] >> 6) & 0x00000003);
    int second = d[4] & 0x0000003F;
    Calendar calendar = Calendar.getInstance();
    calendar.set(year, month - 1, day, hour, minute, second);
    calendar.set(Calendar.MILLISECOND, 0);
    return calendar.getTime();
}