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 getNextDateByMonth(String s, int i) {

    SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyyMMdd");
    java.util.Date date = simpledateformat.parse(s, new ParsePosition(0));
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);//ww w.j a va  2 s . c o m
    calendar.add(2, i);
    date = calendar.getTime();
    s = simpledateformat.format(date);
    return s;
}

From source file:Main.java

public static Timestamp getCurrentDate() {

    Calendar c = Calendar.getInstance();
    c.set(c.get(1), c.get(2), c.get(5), 0, 0, 0);
    Timestamp t = new Timestamp(c.getTime().getTime());
    t.setNanos(0);/*  w  w  w.  j a  va 2  s  . c  o m*/
    return t;
}

From source file:Main.java

public static String calendarToString(Calendar cal, String format) {
    SimpleDateFormat dateFormat = new SimpleDateFormat(format);

    return dateFormat.format(cal.getTime());
}

From source file:Main.java

public static String getNextDateByNum(String s, int i) {

    SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyyMMdd");
    java.util.Date date = simpledateformat.parse(s, new ParsePosition(0));
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);//  w ww  .j  a v  a  2s  .  c o m
    calendar.add(5, i);
    date = calendar.getTime();
    s = simpledateformat.format(date);
    return s;
}

From source file:Main.java

public static Date getStartOfMonth(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);/*w ww.  j a v  a  2s.  co  m*/
    calendar.set(Calendar.DATE, 1);
    return calendar.getTime();
}

From source file:Main.java

public static Date rewindToBeginningOfMonth(Date date) {
    Calendar cal = buildFromDate(rewindToBeginningOfDay(date));
    cal.set(Calendar.DAY_OF_MONTH, 1);
    return cal.getTime();
}

From source file:Main.java

@SuppressLint("SimpleDateFormat")
static String futureDate() {
    // take current date and increment
    Calendar cal = Calendar.getInstance(TimeZone.getDefault());
    Date currentLocalTime = cal.getTime();
    SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd");
    date.setTimeZone(TimeZone.getDefault());
    _currentDate = date.format(currentLocalTime);
    try {//from   ww  w .j  a v  a  2  s. c om
        cal.setTime(date.parse(_currentDate));
    } catch (ParseException e) {
        e.printStackTrace();
    }
    cal.add(Calendar.DATE, 30);
    _currentDate = date.format(cal.getTime());
    return _currentDate;
}

From source file:Main.java

public static String parseDate(long timeInMillis) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(timeInMillis);
    Date date = calendar.getTime();
    return formatDate(date);
}

From source file:Main.java

public static String getNowDate(int afterDay) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DAY_OF_MONTH, afterDay);
    return dateFormat.format(calendar.getTime());
}

From source file:Main.java

public static Date addYear(Date date, int step) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);// w  w w.j av  a 2  s .  co m
    calendar.add(Calendar.YEAR, step);
    return calendar.getTime();
}