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:es.tekniker.framework.ktek.util.Utils.java

public static long getTimeinMillis4FullDateTimeGMT(int year, int month, int day, int hours, int minutes,
        int seconds) {
    Calendar c = getCalendarGMT();

    c.set(Calendar.YEAR, year);/*from ww  w  . jav a2s  .  c om*/
    c.set(Calendar.MONTH, month);
    c.set(Calendar.DAY_OF_MONTH, day);

    c.set(Calendar.HOUR_OF_DAY, hours);
    c.set(Calendar.MINUTE, minutes);
    c.set(Calendar.SECOND, seconds);

    System.out.println("New Time: " + c.getTime());

    long timeinmillis = c.getTimeInMillis();
    System.out.println(" system time in millis " + timeinmillis);

    return timeinmillis;
}

From source file:Main.java

public static long getEndOfMonthMs(int year, int month) {
    final Calendar date = Calendar.getInstance();

    date.set(Calendar.YEAR, year);
    date.set(Calendar.MONTH, month);
    date.set(Calendar.DAY_OF_MONTH, date.getActualMaximum(Calendar.DAY_OF_MONTH));
    date.set(Calendar.HOUR_OF_DAY, date.getActualMaximum(Calendar.HOUR_OF_DAY));
    date.set(Calendar.MINUTE, date.getActualMaximum(Calendar.MINUTE));
    date.set(Calendar.SECOND, date.getActualMaximum(Calendar.SECOND));
    date.set(Calendar.MILLISECOND, date.getActualMaximum(Calendar.MILLISECOND));
    return date.getTimeInMillis();
}

From source file:Main.java

public static long getStartOfMonthMs(int year, int month) {
    final Calendar date = Calendar.getInstance();

    date.set(Calendar.YEAR, year);
    date.set(Calendar.MONTH, month);
    date.set(Calendar.DAY_OF_MONTH, date.getActualMinimum(Calendar.DAY_OF_MONTH));
    date.set(Calendar.HOUR_OF_DAY, date.getActualMinimum(Calendar.HOUR_OF_DAY));
    date.set(Calendar.MINUTE, date.getActualMinimum(Calendar.MINUTE));
    date.set(Calendar.SECOND, date.getActualMinimum(Calendar.SECOND));
    date.set(Calendar.MILLISECOND, date.getActualMinimum(Calendar.MILLISECOND));
    return date.getTimeInMillis();
}

From source file:com.twitter.elephanttwin.util.DateUtil.java

/**
 * Convert calendar to HHMM format//www  . j a  v a  2 s .com
 * @param cal calendar
 * @return output string
 */
public static String calendarToHhMmFormat(Calendar cal) {
    return HH_MM_FORMATTER.print(cal.getTimeInMillis());
}

From source file:dsd.dao.ParsedInputFilesDAO.java

public static String FetchStoredPath(eFileType fileType, Calendar date) {
    String storedPath = null;//from w  w  w. j a v  a  2 s  .c o m
    try {
        Connection con = DAOProvider.getDataSource().getConnection();
        try {
            Object[] parameters = new Object[3];
            parameters[0] = new Integer(fileType.getCode());
            parameters[1] = new Integer(fileType.getCode());
            parameters[2] = new Timestamp(date.getTimeInMillis());
            ResultSet results = DAOProvider.SelectTableSecure(tableName, " stored_path ",
                    " type = ? and timestamp = (select max(timestamp) from parsed_input_files where type = ? and timestamp <= ?) ",
                    "", con, parameters);
            while (results.next()) {
                storedPath = results.getString(1);
            }
        } catch (Exception exc) {
            exc.printStackTrace();
        }
        con.close();
    } catch (Exception exc) {
        exc.printStackTrace();
    }
    return storedPath;
}

From source file:de.blizzy.backup.BackupApplication.java

static void scheduleBackupRun(boolean forceRunNow) {
    if (timer != null) {
        if (backupTimerTask != null) {
            backupTimerTask.cancel();/*from w  w  w  . j ava  2  s  . c o m*/
            backupTimerTask = null;
        }

        backupTimerTask = new TimerTask() {
            @Override
            public void run() {
                runBackup();
            }
        };

        if (forceRunNow) {
            timer.schedule(backupTimerTask, 0);
        } else {
            IDialogSettings backupSection = Utils.getSection("backup"); //$NON-NLS-1$
            long lastRun = backupSection.getLong("lastRun"); //$NON-NLS-1$
            Settings settings = settingsManager.getSettings();
            if (settings.isRunHourly()) {
                nextBackupRunTime = lastRun;
            } else {
                Calendar c = Calendar.getInstance();
                c.setTimeInMillis(lastRun);
                c.set(Calendar.HOUR_OF_DAY, settings.getDailyHours());
                c.set(Calendar.MINUTE, settings.getDailyMinutes());
                nextBackupRunTime = c.getTimeInMillis();
            }
            long now = System.currentTimeMillis();
            for (;;) {
                nextBackupRunTime = clearSeconds(nextBackupRunTime);
                if (nextBackupRunTime > now) {
                    break;
                }
                nextBackupRunTime += settings.isRunHourly() ? 60L * 60L * 1000L : 24L * 60L * 60L * 1000L;
            }
            timer.schedule(backupTimerTask, Math.max(nextBackupRunTime - now, 0));
        }
    }
}

From source file:at.florian_lentsch.expirysync.NotifyChecker.java

private static long getFirstStartMillis(Context appContext) {
    final SharedPreferences sharedPref = appContext.getSharedPreferences("main", Context.MODE_PRIVATE);
    long firstStartMillis = sharedPref.getLong(SettingsActivity.KEY_ALERT_TIME, -1);
    if (firstStartMillis == -1) {
        return -1;
    }//  w w w  . j  a  v a2 s  . c o  m

    Calendar midnight = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    midnight.set(Calendar.HOUR_OF_DAY, 0);
    midnight.set(Calendar.MINUTE, 0);
    midnight.set(Calendar.SECOND, 0);
    midnight.set(Calendar.MILLISECOND, 0);

    // add "today at 0:00" to the ms value for the alarm (else the alarm
    // would be scheduled for 1970-01-01):
    firstStartMillis += midnight.getTimeInMillis();

    // if we're already past the alarm time today, we need to add another
    // day:
    if (firstStartMillis <= Calendar.getInstance().getTimeInMillis()) {
        firstStartMillis += AlarmManager.INTERVAL_DAY;
    }

    return firstStartMillis;
}

From source file:com.twitter.elephanttwin.util.DateUtil.java

/**
 * Convert calendar to YYYYMMDD format//from w ww.j a  v a 2s. com
 * @param cal the calendar
 * @return the output string
 */
public static String calendarToYyyyMmDdFormat(Calendar cal) {
    return YYYY_MM_DD_FORMATTER.print(cal.getTimeInMillis());
}

From source file:com.twitter.elephanttwin.util.DateUtil.java

/**
 * Convert calendar to MMDDYYYY format/*  ww  w .  j  a  va 2s  . c  o m*/
 * @param cal the calendar
 * @return the format
 */
public static String calendarToMmDdYyyyFormat(Calendar cal) {
    return MM_DD_YYYY_FORMATTER.print(cal.getTimeInMillis());
}

From source file:com.aurel.track.fieldType.bulkSetters.DateBulkSetter.java

private static void calculateOffset(BulkTranformContext bulkTranformContext, Integer fieldID,
        Integer parameterCode, Object targetValue, boolean earliest) {
    List<TWorkItemBean> selectedWorkItems = bulkTranformContext.getSelectedWorkItems();
    Map<Integer, Object> valueCache = bulkTranformContext.getValueCache();
    Date targetDate = null;//  w  w  w.ja v  a2  s. c  o  m
    try {
        targetDate = (Date) targetValue;
    } catch (Exception e) {
        LOGGER.warn("Converting the target value " + targetValue + " to Date failed with " + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
    }
    if (targetDate == null || selectedWorkItems == null) {
        //set to 0 to mark it as calculated (avoid finding the offset for each workItem). 0 means no change anyway
        valueCache.put(fieldID, Integer.valueOf(0));
        return;
    }
    Date extremeDate = null;
    for (TWorkItemBean workItemBean : selectedWorkItems) {
        Object value = workItemBean.getAttribute(fieldID, parameterCode);
        if (value != null) {
            Date actualDate = (Date) value;
            if (extremeDate == null) {
                extremeDate = actualDate;
            } else {
                if ((earliest && actualDate.before(extremeDate))
                        || !earliest && actualDate.after(extremeDate)) {
                    extremeDate = actualDate;
                }
            }
        }
    }
    if (extremeDate == null) {
        //set to 0 to mark it as calculated (avoid finding the offset for each workItem). 0 means no change anyway
        valueCache.put(fieldID, Integer.valueOf(0));
    } else {
        Calendar targetCalendar = Calendar.getInstance();
        targetCalendar.setTime(targetDate);
        Calendar extremeCalendar = Calendar.getInstance();
        extremeCalendar.setTime(extremeDate);
        long diff = targetCalendar.getTimeInMillis() - extremeCalendar.getTimeInMillis();
        //daylight saving correction
        double days = diff * 1.0 / (1000 * 60 * 60 * 24);
        int intDays = (int) Math.round(days);
        valueCache.put(fieldID, Integer.valueOf(intDays));
    }
}