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 toYYYYMM(Calendar source) {
    if (source != null) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM", Locale.getDefault());
        return format.format(source.getTime());
    }/*  ww  w  .  java 2s  .c  om*/
    return null;
}

From source file:Main.java

public static String GetPostCommentTime(long milliseconds) {
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(milliseconds);/*  www . j a  va  2 s .  c o m*/
    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd HH:mm");
    return sdf.format(cal.getTime());
}

From source file:Main.java

public static Date startOfNextWeek() {
    Calendar cal = Calendar.getInstance();

    cal.setTime(startOfThisWeek());/*from w w  w.ja v a2s .  co  m*/
    cal.add(Calendar.WEEK_OF_YEAR, 1);

    return cal.getTime();
}

From source file:Main.java

public static Date trim(Date date) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);/*w  ww  .  j  a  va2s. c o m*/
    cal.set(HOUR_OF_DAY, 0);
    cal.set(MINUTE, 0);
    cal.set(SECOND, 0);
    cal.set(MILLISECOND, 0);
    return cal.getTime();
}

From source file:Main.java

public static String getFormatDate(int step) {
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DATE, step);
    SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
    String str = sf.format(cal.getTime());
    return str;//w w w . j av a  2  s .c  o  m
}

From source file:Main.java

/**
 * Converts time in dos format to Java format
 * @param dosTime/*from ww  w.  j  ava  2 s  .com*/
 * @return time in java format
 */
public static long dosToJavaTme(int dosTime) {
    int sec = 2 * (dosTime & 0x1f);
    int min = (dosTime >> 5) & 0x3f;
    int hrs = (dosTime >> 11) & 0x1f;
    int day = (dosTime >> 16) & 0x1f;
    int mon = ((dosTime >> 21) & 0xf) - 1;
    int year = ((dosTime >> 25) & 0x7f) + 1980;

    Calendar cal = Calendar.getInstance();
    cal.set(year, mon, day, hrs, min, sec);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTime().getTime();
}

From source file:Main.java

public static String getDateFromSeconds(long secs) {
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(secs * 1000L);/*w w w.  j a va 2 s  .co m*/
    SimpleDateFormat format1 = new SimpleDateFormat("dd.MM.yyyy");
    return format1.format(c.getTime());
}

From source file:Main.java

/**
 * Returns date before given days/*from w  ww.  j  a v a  2  s . c  o m*/
 *
 * @param days days to before
 * @return string date string before days
 */
public static String getDateBefore(int days) {
    Date today = new Date();
    Calendar cal = new GregorianCalendar();
    cal.setTime(today);
    cal.add(Calendar.DAY_OF_MONTH, days * -1);
    Date date = cal.getTime();
    SimpleDateFormat gmtFormat = new SimpleDateFormat();
    gmtFormat.applyPattern("yyyy-MM-dd 00:00:00");
    TimeZone gmtTime = TimeZone.getTimeZone("GMT");
    gmtFormat.setTimeZone(gmtTime);
    return gmtFormat.format(date);
}

From source file:com.baidu.fsg.uid.utils.DateUtils.java

/**
 * Get current day using format date by 'yyyy-MM-dd HH:mm:ss' pattern
 *
 * @return//from  w ww .ja v  a  2s  . c om
 * @author yebo
 */
public static String getCurrentDayByDayPattern() {
    Calendar cal = Calendar.getInstance();
    return formatByDayPattern(cal.getTime());
}

From source file:Main.java

/**
 * Get First Date of month/*from  w  ww .  j  a  v a2s  .  c  om*/
 */
public static Date getFirstDateOfMonth(int month, int year) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(year, month, 1);
    calendar.set(Calendar.DATE, calendar.getActualMinimum(Calendar.DATE));
    return calendar.getTime();
}