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 String getNextHourDateTime() {
    Calendar c = Calendar.getInstance();
    c.add(Calendar.HOUR, 1);//from w  w w . j ava 2 s  .c  o  m
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:MM:ss");
    String nextTime = sdf.format(new Date(c.getTimeInMillis()));
    return nextTime;
}

From source file:de.otto.mongodb.profiler.web.AbstractController.java

protected static long lowerBoundary(int diffHours) {
    final Calendar cal = Calendar.getInstance(Locale.ENGLISH);
    cal.add(Calendar.HOUR, diffHours);
    return cal.getTimeInMillis();
}

From source file:Main.java

public static void copyTo(Calendar from, Calendar to) {
    int year = from.get(Calendar.YEAR);
    int month = from.get(Calendar.MONTH);
    int day = from.get(Calendar.DAY_OF_MONTH);
    to.set(year, month, day);/*from   w  w  w. j av  a2  s  .  c  o m*/
    to.getTimeInMillis();
}

From source file:Main.java

/**
 * Add date time with almost one year./*w w  w  .  jav  a2  s.co m*/
 *
 * @param listing     the listing
 * @param currentTime the current time
 * @param isPast      true/false if past time
 */
private static void addDateTimeWithAlmostOneYear(final List<Long> listing, final long currentTime,
        final boolean isPast) {
    final Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(currentTime);
    calendar.add(Calendar.MONTH, isPast ? -12 : 12);
    listing.add(calendar.getTimeInMillis());
}

From source file:Main.java

public static List<String> getOldWeekDays() {
    final Calendar c = Calendar.getInstance();
    String[] months = new String[8];
    for (int i = 0; i < 8; i++) {
        months[i] = new SimpleDateFormat("MM.dd").format(new Date(c.getTimeInMillis()));
        c.add(Calendar.DAY_OF_MONTH, -1);
    }/*from   www .  ja  v a 2s  .  c  o m*/
    return Arrays.asList(months);
}

From source file:Main.java

/**
 * Add date time with one day./*from w w w .j  a v  a 2  s .  c om*/
 *
 * @param listing     the listing
 * @param currentTime the current time
 * @param isPast      true/false if past time
 */
private static void addDateTimeWithOneDay(final List<Long> listing, final long currentTime,
        final boolean isPast) {
    final Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(currentTime);
    calendar.add(Calendar.DAY_OF_MONTH, isPast ? -1 : 1);
    listing.add(calendar.getTimeInMillis());
}

From source file:Main.java

public static long today9am() {
    Calendar c = Calendar.getInstance();
    c.set(Calendar.HOUR_OF_DAY, 9);
    c.set(Calendar.MINUTE, 0);//from  w  ww  . j a  va2 s  . co m
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    return c.getTimeInMillis();
}

From source file:Main.java

/**
 * Add date time with almost one month.//w ww  .j a  v  a 2 s . c  o m
 *
 * @param listing     the listing
 * @param currentTime the current time
 * @param isPast      true/false if past time
 */
private static void addDateTimeWithAlmostOneMonth(final List<Long> listing, final long currentTime,
        final boolean isPast) {
    final Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(currentTime);
    calendar.add(Calendar.DAY_OF_MONTH, isPast ? -30 : 30);
    listing.add(calendar.getTimeInMillis());
}

From source file:Main.java

/**
 * Add date time with ten days./*from w w w  . j ava2  s.  co m*/
 *
 * @param listing     the listing
 * @param currentTime the current time
 * @param isPast      true/false if past time
 */
private static void addDateTimeWithTenDays(final List<Long> listing, final long currentTime,
        final boolean isPast) {
    final Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(currentTime);
    calendar.add(Calendar.DAY_OF_MONTH, isPast ? -10 : 10);
    listing.add(calendar.getTimeInMillis());
}

From source file:Main.java

public static long getSmallHourTimestamp() {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR, 0);/*from  w ww .j  ava  2 s.c o  m*/
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTimeInMillis();
}