Example usage for java.util GregorianCalendar getTimeInMillis

List of usage examples for java.util GregorianCalendar getTimeInMillis

Introduction

In this page you can find the example usage for java.util GregorianCalendar 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 currentWeekInMills() {
    GregorianCalendar gregoriancalendar = new GregorianCalendar();
    GregorianCalendar gregoriancalendar1 = new GregorianCalendar(gregoriancalendar.get(1),
            gregoriancalendar.get(2), gregoriancalendar.get(5));
    gregoriancalendar1.setTimeZone(GMT);
    gregoriancalendar1.add(6, -(gregoriancalendar.get(7) - gregoriancalendar.getFirstDayOfWeek()));
    return gregoriancalendar1.getTimeInMillis();
}

From source file:Main.java

public static int getDatePeriod(String startDate, String endDate) {

    String[] date1 = startDate.split("-");
    String[] date2 = endDate.split("-");
    GregorianCalendar gc1 = new GregorianCalendar(Integer.parseInt(date1[0]), Integer.parseInt(date1[1]),
            Integer.parseInt(date1[2]));
    GregorianCalendar gc2 = new GregorianCalendar(Integer.parseInt(date2[0]), Integer.parseInt(date2[1]),
            Integer.parseInt(date2[2]));
    long longDate1 = gc1.getTimeInMillis();
    long longDate2 = gc2.getTimeInMillis();
    long period = longDate2 - longDate1;
    period /= 24 * 60 * 60 * 1000;/*from w w w.ja v  a  2 s . co m*/
    return (int) period;
}

From source file:Main.java

public static long convertTime(long time) {
    GregorianCalendar t1 = new GregorianCalendar(TimeZone.getTimeZone("America/Los_Angeles"));
    t1.setTimeInMillis(time);//from  w  ww .  ja  v  a 2  s  . co  m
    GregorianCalendar t2 = new GregorianCalendar();
    t2.set(t1.get(GregorianCalendar.YEAR), t1.get(GregorianCalendar.MONTH),
            t1.get(GregorianCalendar.DAY_OF_MONTH), t1.get(GregorianCalendar.HOUR_OF_DAY),
            t1.get(GregorianCalendar.MINUTE), t1.get(GregorianCalendar.SECOND));
    return t2.getTimeInMillis();
}

From source file:com.projity.util.DateTime.java

public static long midnightToday() {
    GregorianCalendar cal = calendarInstance();
    return dayFloor(cal.getTimeInMillis());
}

From source file:com.projity.util.DateTime.java

public static long midnightTomorrow() {
    GregorianCalendar cal = calendarInstance();
    cal.add(Calendar.DATE, 1);//  w  ww  .  j  a va2  s.  c  o  m
    return dayFloor(cal.getTimeInMillis());
}

From source file:com.projity.util.DateTime.java

/**
 * Get an integer for the date in form YYYYMMDD where the months go from 1 to 12 (unlike calendar where they go from 0 to 11)
 * @param date/*from w ww .j av  a2s.c om*/
 * @return
 */
public static long fromId(int id) {
    GregorianCalendar cal = DateTime.calendarInstance(id / 10000, (id / 100) % 100 - 1, id % 100);
    return cal.getTimeInMillis();

}

From source file:com.projity.util.DateTime.java

public static long midnightNextDay(long d) {
    d = dayFloor(d);//  w  w  w. j  av a 2 s  .c o  m
    GregorianCalendar cal = calendarInstance();
    cal.setTimeInMillis(d);
    cal.add(Calendar.DATE, 1);
    return cal.getTimeInMillis();
}

From source file:org.amanzi.neo.core.period.Period.java

/**
 * add one period//  w w w. j av a2s .co m
 * 
 * @param time - timestamp
 * @param period - period @see Calendar
 * @return timestamp+ 1 period
 */
private static Long addOnePeriod(final Long time, final int period) {
    final GregorianCalendar cl = new GregorianCalendar();
    cl.setTimeInMillis(time);
    cl.add(period, 1);
    return cl.getTimeInMillis();
}

From source file:com.projity.util.DateTime.java

public static long nextDay(long day) {
    GregorianCalendar d = DateTime.calendarInstance();
    d.setTimeInMillis(day);/*from   ww w.  j av  a 2 s. c  om*/
    d.add(GregorianCalendar.DAY_OF_MONTH, 1);
    return d.getTimeInMillis();
}

From source file:com.projity.util.DateTime.java

public static long hour24() {
    GregorianCalendar cal = DateTime.calendarInstance();
    cal.setTimeInMillis(0);/*  www.  ja  va2  s.c o m*/
    cal.set(GregorianCalendar.HOUR_OF_DAY, 24);
    return cal.getTimeInMillis();
}