private String getDate(String timeStampStr, String format) { DateFormat formatter = new SimpleDateFormat(format); long timeStamp = Long.parseLong(timeStampStr); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(timeStamp); return formatter.format(calendar.getTime()); }
/** Initializes contained components. */ private void initComponents() { final SimpleDateFormat format = new SimpleDateFormat("mm:ss"); final Calendar c = Calendar.getInstance(); final JLabel counter = new JLabel(); counter.setForeground(Color.red); counter.setFont(counter.getFont().deriveFont((float) (counter.getFont().getSize() + 5))); setLayout(new GridBagLayout()); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); GridBagConstraints constraints = new GridBagConstraints(); JLabel messageLabel = new JLabel( GuiActivator.getResources().getI18NString("service.gui.security.SECURITY_ALERT")); messageLabel.setForeground(Color.WHITE); constraints.anchor = GridBagConstraints.CENTER; constraints.fill = GridBagConstraints.NONE; constraints.gridx = 0; constraints.gridy = 0; add(messageLabel, constraints); constraints.anchor = GridBagConstraints.CENTER; constraints.fill = GridBagConstraints.NONE; constraints.gridx = 0; constraints.gridy = 1; add(counter, constraints); ZrtpControl zrtpControl = null; if (securityControl instanceof ZrtpControl) zrtpControl = (ZrtpControl) securityControl; long initialSeconds = 0; if (zrtpControl != null) initialSeconds = zrtpControl.getTimeoutValue(); c.setTimeInMillis(initialSeconds); counter.setText(format.format(c.getTime())); if (initialSeconds > 0) timer.schedule( new TimerTask() { @Override public void run() { if (c.getTimeInMillis() - 1000 > 0) { c.add(Calendar.SECOND, -1); counter.setText(format.format(c.getTime())); } } }, 1000, 1000); }
public static long getTimeInMillis(int nType, long lDate, int nRoll) { Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(lDate); if (nType == MONTH) cal.add(Calendar.MONTH, nRoll); // 월 단위 else if (nType == YEAR) cal.add(Calendar.YEAR, nRoll); // 년 단위 else if (nType == HOUR) cal.add(Calendar.HOUR, nRoll); // 시 단위 else cal.add(Calendar.DATE, nRoll); // 일 단위 return cal.getTimeInMillis(); }
/** * Gets the value of this datetime as a milliseconds value for {@link java.sql.Date}. * * @param zone time zone in which to generate a time value for */ public long getJdbcDate(TimeZone zone) { Calendar cal = getCalendar(DateTimeUtil.gmtZone); cal.setTimeInMillis(getDateValue()); int year = cal.get(Calendar.YEAR); int doy = cal.get(Calendar.DAY_OF_YEAR); cal.clear(); cal.setTimeZone(zone); cal.set(Calendar.YEAR, year); cal.set(Calendar.DAY_OF_YEAR, doy); return cal.getTimeInMillis(); }
/** * Gets the value of this datetime as a milliseconds value for {@link java.sql.Timestamp}. * * @param zone time zone in which to generate a time value for */ public long getJdbcTimestamp(TimeZone zone) { Calendar cal = getCalendar(DateTimeUtil.gmtZone); cal.setTimeInMillis(internalTime); int year = cal.get(Calendar.YEAR); int doy = cal.get(Calendar.DAY_OF_YEAR); int hour = cal.get(Calendar.HOUR_OF_DAY); int minute = cal.get(Calendar.MINUTE); int second = cal.get(Calendar.SECOND); int millis = cal.get(Calendar.MILLISECOND); cal.clear(); cal.setTimeZone(zone); cal.set(Calendar.YEAR, year); cal.set(Calendar.DAY_OF_YEAR, doy); cal.set(Calendar.HOUR_OF_DAY, hour); cal.set(Calendar.MINUTE, minute); cal.set(Calendar.SECOND, second); cal.set(Calendar.MILLISECOND, millis); return cal.getTimeInMillis(); }