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 getCurrentUTCTime() {
    // Set device's time zone to UTC
    TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
    Calendar calendar = Calendar.getInstance();
    return calendar.getTime();
}

From source file:Main.java

public static boolean inBetweenDate(Calendar first, Calendar last) {

    Date min = first.getTime();
    Date max = last.getTime();// w w  w  .j  a  v a2  s  .c  om

    boolean check = max.before(min);
    boolean check2 = max.equals(min);

    return !(check || check2);
}

From source file:Main.java

public static String getTodayString(String formatString) {
    Calendar cal = Calendar.getInstance();
    return formatDate(cal.getTime(), formatString);
}

From source file:Main.java

/**
 * Method to convert a calendar object to java's epoch date keeping only the
 * time information/*from   w w  w.j av a2s.  c o m*/
 */
public static Date toEpochDate(Calendar calendar) {
    return new Date(Time.valueOf(new SimpleDateFormat("HH:mm:ss").format(calendar.getTime())).getTime());
}

From source file:Main.java

public static String timeToString() {
    SimpleDateFormat sdf = new SimpleDateFormat("ddMMyyyyhhmmss", Locale.getDefault());
    Calendar data = Calendar.getInstance();
    return sdf.format(data.getTime());
}

From source file:Main.java

/**
 * convert calendar to date string with format yyyy-MM-dd
 *
 * @param calendar//from ww  w.j ava  2 s  .c  om
 * @return
 */
public static String calendar2Str(Calendar calendar) {
    return formatYYYY_MM_DD.format(calendar.getTime());
}

From source file:Main.java

public static String getHoraAtual() {
    DateFormat df = new SimpleDateFormat("HH:mm");
    Calendar cal = Calendar.getInstance();

    return df.format(cal.getTime());

}

From source file:Main.java

private static boolean isBeforeMonths(int months, Date aDate) {
    Calendar calendar = Calendar.getInstance();
    calendar.add(MONTH, months);/*from w w w .  j  a  va 2s .  c  om*/
    return aDate.compareTo(calendar.getTime()) < 0;
}

From source file:Main.java

public static Date currentDate() {
    Calendar calendar = Calendar.getInstance();
    return calendar.getTime();
}

From source file:Main.java

public static String date2() {
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    Calendar c = Calendar.getInstance();
    String date = format.format(c.getTime());
    return date;/*from w  ww .j a  v a2 s.  com*/
}