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 round2Hour(Date date) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);// w w  w . ja  v  a  2 s  .c  o m
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTime();
}

From source file:models.Activation.java

public static Activation generateActivationCode(User u, int validForDays) {
    Activation a = new Activation();
    a.user = u;//from w  ww .j av  a2s. c o m
    u.activation = a;
    a.activationCode = RandomStringUtils.randomAlphanumeric(40);

    Calendar c = Calendar.getInstance();
    c.add(Calendar.DATE, validForDays);

    a.expirationDate = c.getTime();

    a.save();
    u.save();

    return a;
}

From source file:Main.java

/**
 * Get a string representation of the current date / time in a format suitable for a file name.
 * @return A string representation of the current date / time.
 *//*from   w  w  w.jav a 2s .  c  om*/
public static String getNowForFileName() {
    Calendar c = Calendar.getInstance();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd-HHmmss");

    return sdf.format(c.getTime());
}

From source file:Main.java

public static Date getNextDay(Date presentDate) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(presentDate);/*from  w  ww  .  j av  a  2s  . co m*/
    calendar.add(Calendar.DAY_OF_MONTH, 1);
    presentDate = calendar.getTime();
    return presentDate;
}

From source file:Main.java

public static String formatDT() {
    Calendar c = Calendar.getInstance();
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String formattedDate = df.format(c.getTime());
    System.out.println(formattedDate);
    return formattedDate;
}

From source file:Main.java

public static String now(String dateFormat) {
    Calendar cal = Calendar.getInstance();
    SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
    return sdf.format(cal.getTime());
}

From source file:Main.java

public static Date getPreNDay(Date presentDate, int n) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(presentDate);//  w  w w . ja v  a  2  s  . c om
    calendar.add(Calendar.DAY_OF_MONTH, -n);
    presentDate = calendar.getTime();
    return presentDate;
}

From source file:Main.java

public static Date getPreDay(Date presentDate) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(presentDate);/* www  .ja  v  a2 s.  com*/
    calendar.add(Calendar.DAY_OF_MONTH, -1);
    presentDate = calendar.getTime();
    return presentDate;
}

From source file:Main.java

private static Date getTomorrowMorning4am() {
    Calendar tomorrow = new GregorianCalendar();
    tomorrow.add(Calendar.DATE, fONE_DAY);
    Calendar result = new GregorianCalendar(tomorrow.get(Calendar.YEAR), tomorrow.get(Calendar.MONTH),
            tomorrow.get(Calendar.DATE), fFOUR_AM, fZERO_MINUTES);
    return result.getTime();
}

From source file:Main.java

public static Date getDateMinuteBefore(Date originalDate, int minutes) {
    Calendar cal = new GregorianCalendar();
    cal.setTime(originalDate);// w  ww.ja v a2s .  c  o m
    cal.add(Calendar.MINUTE, minutes * -1);
    return cal.getTime();
}