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 getTimeOfDayFromString(String dateString) {
    java.util.Calendar c = getCalendarFromStringDate(dateString);
    SimpleDateFormat format = new SimpleDateFormat("HH:mm");
    return format.format(c.getTime());
}

From source file:Main.java

public static String currentTime() {
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(firstCall + (offset * 1000 * 60));
    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
    offset++;//from   w  w w .  j av  a 2  s  .com
    return sdf.format(cal.getTime());
}

From source file:Main.java

public static Date parseDate(String dateString) {
    Matcher m = DATE_PATTERN.matcher(dateString.trim());
    if (!m.matches()) {
        throw new IllegalArgumentException("\"" + dateString + "\" must be in YYYY-MM-DD format.");
    }/*from   ww  w.j av a 2  s .c o  m*/
    Calendar c = Calendar.getInstance();
    c.set(Integer.parseInt(m.group(1)), Integer.parseInt(m.group(2)) - 1, Integer.parseInt(m.group(3)));
    return c.getTime();
}

From source file:Main.java

public static String GetFormatDateYMStrByMillseconds(long milliseconds) {
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(milliseconds);//from   w  w w  . j  av a  2 s  . c o m
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
    return sdf.format(cal.getTime());
}

From source file:Main.java

public static String getCurTime(String format) {
    long now = System.currentTimeMillis();
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(now);/*from w w w.  j ava  2 s.  co m*/
    SimpleDateFormat sdf = new SimpleDateFormat(format);
    return sdf.format(calendar.getTime());
}

From source file:Main.java

private static Date getDateBefore() {
    Date nowtime = new Date();
    Calendar now = Calendar.getInstance();
    now.setTime(nowtime);//  w  w w  .j  a va 2 s. c o m
    now.set(Calendar.DATE, now.get(Calendar.DATE) - LOG_SAVE_DAYS);
    return now.getTime();
}

From source file:Main.java

public static final String getStandardTime(int minute, int hour) {
    SimpleDateFormat format = new SimpleDateFormat("HH:mm", Locale.CHINA);
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.MINUTE, minute);
    calendar.set(Calendar.HOUR_OF_DAY, hour);
    return format.format(calendar.getTime());
}

From source file:Main.java

public static String updateCalendarTimeAndGetFormat(Calendar cal, int hourOfDay, int minute) {
    cal.set(Calendar.HOUR_OF_DAY, hourOfDay);
    cal.set(Calendar.MINUTE, minute);
    return defaultTimeFormat.format(cal.getTime());
}

From source file:org.activiti.rest.util.JSONUtil.java

public static String formatISO8601Date(Calendar calendar) {
    if (calendar != null) {
        return ISO8601DateFormat.format(calendar.getTime());
    }//from   ww  w .jav  a2 s .com
    return null;
}

From source file:Main.java

public static String getMonthFirstDay() {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));

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