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 getDate(String crisisDate) {
    try {/*ww w  .  j  av  a 2s. c o  m*/
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
        Date date = (Date) formatter.parse(crisisDate);
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        return cal.getTime();
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static String getCurrMonthAfter(int monthDiff, String format) {
    SimpleDateFormat ft = new SimpleDateFormat(format);
    Calendar c = new GregorianCalendar();
    c.add(Calendar.MONTH, monthDiff);
    return ft.format(c.getTime());
}

From source file:Main.java

/**
 * Convert a timestamp to a date./*from   w w w. jav a  2s .  co  m*/
 *
 * @param milliseconds
 * @return
 */
public static Date millisecondsToDate(long milliseconds) {
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(milliseconds);
    return cal.getTime();
}

From source file:Main.java

public static String StampToStringMMddHHmm(long stamp) {

    Date date = null;// ww  w  .  j a  v  a  2  s .c om
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(stamp);
    date = calendar.getTime();

    //       String format = "yyyy-MM-dd HH:mm:ss.SSSZ"; 
    String format = "MM-dd HH:mm";
    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 String getDateFromMillies(long milliSeconds, String dateFormat) {
    SimpleDateFormat formatter = new SimpleDateFormat(dateFormat);
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(milliSeconds);
    return formatter.format(calendar.getTime());
}

From source file:Main.java

public static Date makeDate(int year, int month, int day) {
    Calendar cal = Calendar.getInstance();
    cal.clear();/*from  w w w  . j av  a2 s  .c  o m*/
    cal.set(year, month - 1, day, 0, 0, 0);
    return cal.getTime();
}

From source file:Main.java

public static String StampToyyyyMMddHHmmss(long stamp) {

    Date date = null;/*from   w  w w .  j  a  va 2  s.  c o m*/
    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"; 
    SimpleDateFormat sdf = new SimpleDateFormat(format);
    //sdf.setTimeZone(TimeZone.getTimeZone("UTC"));   
    sdf.setTimeZone(TimeZone.getTimeZone("PRC"));

    String time = sdf.format(date);
    return time.substring(0, "yyyy-MM-dd HH:mm:ss".length());

}

From source file:Main.java

public static String calendar2LongString(Calendar calendar) {
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:00");
    return format.format(calendar.getTime());
}

From source file:Main.java

public static String getDate(long milliSeconds) {
    SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss a");
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(milliSeconds);
    return formatter.format(calendar.getTime());
}

From source file:Main.java

public static String getCurrentDateTimeinMillis() {
    /*/*from w  w  w. j a  v  a  2s .  c  o  m*/
    long millis = System.currentTimeMillis()%1000;
    String millisStr;
    if(millis < 10){
    millisStr = "00" + String.valueOf(millis);
    }else if(millis < 100){
    millisStr = "0" + String.valueOf(millis);
    }else{
    millisStr = String.valueOf(millis);
    }
    String currentDateTimeinMillis = Helper.getCurrentDateTime()
        + "." + millisStr;*/

    DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd HHmmss.SSS");
    Calendar cal = Calendar.getInstance();
    String currentDateTimeinMillis = dateFormat.format(cal.getTime());
    return currentDateTimeinMillis;
}