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 String calendarDateForLocale(Calendar calendar, Locale locale) {
    DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.SHORT, locale);
    return dateFormatter.format(calendar.getTime());
}

From source file:Main.java

public static Date getTimeFrom(int year, int month, int day, int hour, int minute, int second) {
    Calendar calendar = new GregorianCalendar(year, month, day, hour, minute, second);
    calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
    return calendar.getTime();
}

From source file:Main.java

public static String getCurrentDateByOffset(String format, int calendarField, int offset) {
    String mDateTime = null;//from   www  .j  av a 2s.  com
    try {
        SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format);
        Calendar c = new GregorianCalendar();
        c.add(calendarField, offset);
        mDateTime = mSimpleDateFormat.format(c.getTime());
    } catch (Exception e) {
        e.printStackTrace();
    }
    return mDateTime;

}

From source file:Main.java

public static Date moveToToday(Date date) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);/*ww w  .java2s . co m*/
    int hour = cal.get(Calendar.HOUR_OF_DAY);
    int minute = cal.get(Calendar.MINUTE);

    Calendar result = Calendar.getInstance();
    result.set(Calendar.HOUR_OF_DAY, hour);
    result.set(Calendar.MINUTE, minute);
    return result.getTime();
}

From source file:Main.java

@SuppressLint("SimpleDateFormat")
public static String getFormattedCurrentDate() {
    Calendar c = Calendar.getInstance();
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String formattedDate = df.format(c.getTime());

    return formattedDate;
}

From source file:Main.java

public static String yesterday() {
    Calendar c = Calendar.getInstance();
    c.add(Calendar.DATE, -1);/*from  w w  w.j ava 2s  .co  m*/
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    return df.format(c.getTime());
}

From source file:Main.java

public static String getPrettyDate(int year, int month, int day) {
    Calendar c = new GregorianCalendar(year, month, day);
    DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.LONG);
    return dateFormat.format(c.getTime());
}

From source file:Main.java

public static String getDateString(int year, int month, int day) {
    Calendar c = Calendar.getInstance();
    c.set(year, month, day);//from  ww  w.j  a  va  2 s . c  om
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    return sdf.format(c.getTime());
}

From source file:Main.java

public static String getPrettyDate(Calendar c) {
    if (c != null) {
        SimpleDateFormat dateFormatter = new SimpleDateFormat("EEE, MMM d");
        return dateFormatter.format(c.getTime());
    } else {//from   ww w  .  ja va 2 s .  c  o  m
        return "";
    }
}

From source file:Main.java

public static String getStringFromDate(Calendar date, String format) {
    String string;//ww w  .  j a  va 2 s . co  m

    SimpleDateFormat form = new SimpleDateFormat(format, Locale.US);
    string = form.format(date.getTime());

    return string;
}