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 int StampToDateInt(long stamp) {
    int date = 0;

    Date datetime = null;/*from  w ww  .  j  ava 2  s.  c o  m*/
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(stamp);
    datetime = calendar.getTime();

    String format = STAMP_TO_DATE_INT;
    SimpleDateFormat sdf = new SimpleDateFormat(format);
    sdf.setTimeZone(TimeZone.getTimeZone(TIME_ZONE_PRC));

    try {
        date = Integer.parseInt(sdf.format(datetime));
    } catch (Exception e) {
        e.printStackTrace();
    }
    //Log.i("StampHelper", "date_int:"+date);
    return date;
}

From source file:Main.java

public static String getDateLable(Context context, Calendar calendar) {
    SimpleDateFormat sdf = new SimpleDateFormat(FORMAT_SHOW_DATE);
    final String dateDisplay = sdf.format(calendar.getTime());
    return dateDisplay;
}

From source file:Main.java

public static String StampToString(long stamp) {
    /*//from  www  .  j  av a 2  s.  c om
     String[] formats = new String[] {  
     "yyyy-MM-dd",   
     "yyyy-MM-dd HH:mm",  
     "yyyy-MM-dd HH:mmZ",   
     "yyyy-MM-dd HH:mm:ss.SSSZ",
     "yyyy-MM-dd'T'HH:mm:ss.SSSZ",
     }; 
     */
    Date date = null;
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(stamp);
    date = calendar.getTime();

    //       String format = "yyyy-MM-dd HH:mm:ss.SSSZ"; 
    String format = "yyyy-MM-dd HH:mm:ss.SSSZ";
    SimpleDateFormat sdf = new SimpleDateFormat(format);
    //sdf.setTimeZone(TimeZone.getTimeZone("UTC"));   
    sdf.setTimeZone(TimeZone.getTimeZone("PRC"));

    return sdf.format(date);

}

From source file:Main.java

public static Date plusHours(Date date, int n) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);/* w w w  .  j  av  a 2 s .  c  om*/
    calendar.add(Calendar.HOUR_OF_DAY, n);
    return calendar.getTime();
}

From source file:Main.java

/**
 * Return date in specified format.// w w  w.  j  a v a2s. c  o m
 *
 * @param milliSeconds Date in milliseconds
 * @param dateFormat   Date format
 * @return String representing date in specified format
 */
public static String getDate(long milliSeconds, String dateFormat) {
    // Create a DateFormatter object for displaying date in specified format.
    SimpleDateFormat formatter = new SimpleDateFormat(dateFormat);

    // Create a calendar object that will convert the date and time value in milliseconds to date.
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(milliSeconds);
    return formatter.format(calendar.getTime());
}

From source file:Main.java

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

From source file:Main.java

public static Date addDate(Date date, int days) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);//from  w w w  .ja  v a2 s.c  o  m
    calendar.add(Calendar.DATE, days);
    return calendar.getTime();
}

From source file:Main.java

public static Date getDateBefore(Date d, int day) {
    Calendar now = Calendar.getInstance();
    now.setTime(d);/*  ww w. java  2s  .c  o  m*/
    now.set(Calendar.DATE, now.get(Calendar.DATE) - day);
    return now.getTime();
}

From source file:Main.java

public static Date getNextDay(Date date) {
    Calendar day = Calendar.getInstance();
    day.setTime(date);//from www  . j av a  2 s.c o  m
    day.add(Calendar.DAY_OF_MONTH, 1);

    return day.getTime();
}

From source file:Main.java

public static String getCurrentDate() {
    String date = null;/*from   w  w w  .  j a v  a  2  s. c  o m*/
    Calendar cal = Calendar.getInstance();
    DateFormat dfm = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
    date = dfm.format(cal.getTime());
    return date;
}