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 getNextDateByYear(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);//from  w ww  .j av  a 2s.  co  m
    calendar.add(Calendar.YEAR, i);
    date = calendar.getTime();
    s = simpledateformat.format(date);
    return s;
}

From source file:Main.java

public static String getTimeDisplay(Calendar cal) {

    SimpleDateFormat dateFormat = new SimpleDateFormat("hh:mm aa", Locale.getDefault());
    return dateFormat.format(cal.getTime());
}

From source file:Main.java

/**
 * ????date???n???????/*from   w w w.j a  v a  2  s  .  c  o  m*/
 */
public static Date getDateAfter(Date date, int n) {
    Calendar now = Calendar.getInstance();
    now.setTime(date);
    now.set(Calendar.DATE, now.get(Calendar.DATE) + n);
    return now.getTime();
}

From source file:Main.java

public static Date addMinutes(Date date, int min) {
    if (date == null) {
        return null;
    }//from   w  ww. j av a2  s.com

    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    calendar.add(Calendar.MINUTE, min);
    return calendar.getTime();
}

From source file:Main.java

public static Date datePlusNDay(Date date, int n) {
    Calendar calendar = Calendar.getInstance();

    calendar.setTime(date);//  w w w.  j  av  a 2  s.c o  m
    calendar.add(Calendar.DAY_OF_YEAR, n);

    return calendar.getTime();
}

From source file:Main.java

public static String calendarToString(Calendar calendar) {
    SimpleDateFormat formatter = new SimpleDateFormat("yyy-MM-dd HH:mm", Locale.CHINESE);
    return formatter.format(calendar.getTime());
}

From source file:Main.java

public static String getTimeStamp() {
    Calendar cal = Calendar.getInstance();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
    return sdf.format(cal.getTime());
}

From source file:Main.java

public static String toDate(Date date, int add) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);//from   w ww . j av a 2s. co  m
    calendar.add(Calendar.DATE, add);
    return toDate(calendar.getTime());
}

From source file:Main.java

public static String getTomorrowDate() {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
    Date date = new Date(System.currentTimeMillis());

    Calendar cal = Calendar.getInstance();
    cal.setTime(date);//  w w  w.  ja v  a 2 s.c o m
    cal.add(Calendar.DAY_OF_YEAR, +1);

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

From source file:Main.java

public static String getYesterdayData() {
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DATE, -1);/*from w w  w  . j a v  a2 s.  com*/
    String yesterday = new SimpleDateFormat("yyyy-MM-dd ").format(cal.getTime());
    return yesterday;
}