Example usage for java.util Calendar getTimeInMillis

List of usage examples for java.util Calendar getTimeInMillis

Introduction

In this page you can find the example usage for java.util Calendar getTimeInMillis.

Prototype

public long getTimeInMillis() 

Source Link

Document

Returns this Calendar's time value in milliseconds.

Usage

From source file:Main.java

public static long getTodayMills() {
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(System.currentTimeMillis());
    c.set(Calendar.HOUR_OF_DAY, 0);
    c.set(Calendar.MINUTE, 0);//  w  w w. jav  a  2s .com
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    return c.getTimeInMillis();
}

From source file:com.github.jgility.core.util.ReleasePlanningUtils.java

private static Calendar addDayOffset(final Calendar date, long offset) {
    Calendar newDate = new GregorianCalendar();
    newDate.setTimeInMillis(date.getTimeInMillis());
    newDate.add(Calendar.DAY_OF_MONTH, safeLongToInt(offset));
    return newDate;
}

From source file:io.wcm.caconfig.extensions.references.impl.ConfigurationReferenceProvider.java

private static long getLastModifiedOf(Page page) {
    Calendar lastModified = page.getLastModified();
    return lastModified != null ? lastModified.getTimeInMillis() : 0;
}

From source file:Main.java

/**
 * getDateEnd//  ww  w. ja  va2  s .  c  om
 * @param date the date that needs to be converted to an end date
 * @return a date at 11:59 PM
 */
public static Date getDateEnd(Date date) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    cal.set(Calendar.HOUR_OF_DAY, 23);
    cal.set(Calendar.MINUTE, 59);
    cal.set(Calendar.SECOND, 59);
    cal.set(Calendar.MILLISECOND, 59);
    long time = cal.getTimeInMillis();
    date.setTime(time);
    return date;
}

From source file:Main.java

/**
 * set to the last day of month// w w  w  . ja v a2 s  .  com
 * @param calendar
 */
public static void setToLastDay(Calendar calendar) {
    int year = getYear(calendar);
    int month = getMonth(calendar);
    int maxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    calendar.clear();
    calendar.set(year, month, maxDay);
    calendar.getTimeInMillis();
}

From source file:com.google.cloud.backend.spi.BlobUrlManager.java

private static long getExpiration(int minutesFromNow) {
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.MINUTE, minutesFromNow);
    long expiration = calendar.getTimeInMillis() / 1000L;
    return expiration;
}

From source file:Main.java

/** accurate to day */
public static Calendar getToday() {
    Calendar cal = Calendar.getInstance();
    int year = getYear(cal);
    int month = getMonth(cal);
    int day = getDay(cal);
    cal.clear();/*from w w  w.  j a v a2  s.c o m*/
    cal.set(year, month, day);
    cal.getTimeInMillis();
    return cal;
}

From source file:Main.java

public static String getCurrentTimeString(int s) {
    //s=0 for star time s=1 for end time
    Calendar currentCalendar = Calendar.getInstance();
    int hours = currentCalendar.get(Calendar.HOUR_OF_DAY);
    int minutes = currentCalendar.get(Calendar.MINUTE);

    if (minutes < 30) {
        currentCalendar.setTimeInMillis(currentCalendar.getTimeInMillis() + (30 - minutes) * 60 * 1000);
    }// w  w  w .  ja va 2s .c o  m
    if (minutes > 30) {
        currentCalendar.setTimeInMillis(currentCalendar.getTimeInMillis() + (60 - minutes) * 60 * 1000);
    }
    if (s == 1)
        currentCalendar.setTimeInMillis(currentCalendar.getTimeInMillis() + 30 * 60 * 1000);

    return timeFormat.format(currentCalendar.getTimeInMillis());
}

From source file:Main.java

public static long getBeginOfCurrentDateInMillis() {
    Calendar calendar = Calendar.getInstance();
    calendar.clear(Calendar.HOUR);
    calendar.clear(Calendar.HOUR_OF_DAY);
    calendar.clear(Calendar.MINUTE);
    calendar.clear(Calendar.SECOND);
    calendar.clear(Calendar.MILLISECOND);
    return calendar.getTimeInMillis();
}

From source file:Main.java

public static long getTimeLongTenHours(int year, int month, int day) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(year, month, day);//from   w  w  w  . jav a 2s . com
    calendar.set(Calendar.HOUR_OF_DAY, 10);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    return calendar.getTimeInMillis();
}