List of usage examples for java.util Calendar SECOND
int SECOND
To view the source code for java.util Calendar SECOND.
Click Source Link
get
and set
indicating the second within the minute. From source file:Utils.java
public static Date getEndOfDay(Date day, Calendar cal) { if (day == null) day = new Date(); cal.setTime(day);/* w w w . j ava2 s . c o m*/ cal.set(Calendar.HOUR_OF_DAY, cal.getMaximum(Calendar.HOUR_OF_DAY)); cal.set(Calendar.MINUTE, cal.getMaximum(Calendar.MINUTE)); cal.set(Calendar.SECOND, cal.getMaximum(Calendar.SECOND)); cal.set(Calendar.MILLISECOND, cal.getMaximum(Calendar.MILLISECOND)); return cal.getTime(); }
From source file:com.joken.common.utils.ConverterUtils.java
/** * ?/* w w w .java 2 s .co m*/ * * @param time * :08:30:00 * @param separator * : * @return */ public static Long string2TimeSeconds(String time, String separator) { Calendar cl = Calendar.getInstance(); String[] times = time.split(separator); cl.set(Calendar.HOUR_OF_DAY, Integer.valueOf(times[0])); cl.set(Calendar.MINUTE, Integer.valueOf(times[1])); cl.set(Calendar.SECOND, Integer.valueOf(times[2])); cl.set(Calendar.MILLISECOND, 0); return cl.getTimeInMillis() / 1000; }
From source file:de.codesourcery.eve.skills.util.Misc.java
public static Calendar stripToDay(Date d) { Calendar cal = Calendar.getInstance(); cal.setTime(d);//from w w w. j a v a 2s. c om cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); return cal; }
From source file:Main.java
public static int[] getTime(long time, String timeZone) { Calendar c = Calendar.getInstance(); if (timeZone != null && timeZone.length() != 0) { TimeZone tz = TimeZone.getTimeZone(timeZone); c = Calendar.getInstance(tz); }//from ww w. j a va2 s . c o m c.setTimeInMillis(time); int y = c.get(Calendar.YEAR); int m = c.get(Calendar.MONTH); int d = c.get(Calendar.DAY_OF_MONTH); int hour = c.get(Calendar.HOUR_OF_DAY); int minute = c.get(Calendar.MINUTE); int second = c.get(Calendar.SECOND); return new int[] { y, m, d, hour, minute, second }; }
From source file:Main.java
public static boolean isToday(long dateUtc) { final long currentTime = System.currentTimeMillis(); final Calendar calendarBefore = Calendar.getInstance(); calendarBefore.setTimeInMillis(currentTime); calendarBefore.set(Calendar.HOUR_OF_DAY, 0); calendarBefore.set(Calendar.MINUTE, 0); calendarBefore.set(Calendar.SECOND, 0); calendarBefore.set(Calendar.MILLISECOND, 0); ////from www. j av a2 s .c om final Calendar calendarAfter = Calendar.getInstance(); calendarAfter.setTimeInMillis(currentTime); calendarAfter.set(Calendar.HOUR_OF_DAY, 23); calendarAfter.set(Calendar.MINUTE, 59); calendarAfter.set(Calendar.SECOND, 59); calendarAfter.set(Calendar.MILLISECOND, 250); if ((dateUtc >= calendarBefore.getTimeInMillis()) && (dateUtc <= calendarAfter.getTimeInMillis())) { return true; } return false; }
From source file:Main.java
public static int compare(Calendar date1, Calendar date2) { int i = date1.get(Calendar.YEAR); int j = date2.get(Calendar.YEAR); if (i > j) return 1; if (i < j) return -1; i = date1.get(Calendar.MONTH); j = date2.get(Calendar.MONTH); if (i > j) return 1; if (i < j) return -1; i = date1.get(Calendar.DAY_OF_MONTH); j = date2.get(Calendar.DAY_OF_MONTH); if (i > j) return 1; if (i < j) return -1; i = date1.get(Calendar.HOUR_OF_DAY); j = date2.get(Calendar.HOUR_OF_DAY); if (i > j) return 1; if (i < j) return -1; i = date1.get(Calendar.MINUTE); j = date2.get(Calendar.MINUTE); if (i > j) return 1; if (i < j) return -1; i = date1.get(Calendar.SECOND); j = date2.get(Calendar.SECOND); if (i > j) return 1; if (i < j) return -1; return 0;//from w w w. ja va2 s . c o m }
From source file:edu.zipcloud.core.util.DateUtil.java
public static Date getStartOfDay(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date);//from w w w .j av a 2 s.c o m calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); return calendar.getTime(); }
From source file:DateHelper.java
/** * Calculating age from a current date//from w ww .j a v a2 s . c o m * * @param current * @param birthdate * @return Age from the current (arg) date */ public static float getAge(final Date current, final Date birthdate) { if (birthdate == null) { return 0; } if (current == null) { return getAge(birthdate); } else { final Calendar calend = new GregorianCalendar(); calend.set(Calendar.HOUR_OF_DAY, 0); calend.set(Calendar.MINUTE, 0); calend.set(Calendar.SECOND, 0); calend.set(Calendar.MILLISECOND, 0); calend.setTimeInMillis(current.getTime() - birthdate.getTime()); float result = 0; result = calend.get(Calendar.YEAR) - 1970; result += (float) calend.get(Calendar.MONTH) / (float) 12; return result; } }
From source file:com.liusoft.dlog4j.util.DateUtils.java
/** * ?/*from w w w .j a v a 2 s . c o m*/ * @param date * @param time * @return */ public static Calendar mergeDateTime(Date date, Time time) { Calendar cal = Calendar.getInstance(); if (date != null) cal.setTime(date); if (time != null) { Calendar temp = Calendar.getInstance(); temp.setTime(time); cal.set(Calendar.HOUR_OF_DAY, temp.get(Calendar.HOUR_OF_DAY)); cal.set(Calendar.MINUTE, temp.get(Calendar.MINUTE)); cal.set(Calendar.SECOND, temp.get(Calendar.SECOND)); cal.set(Calendar.MILLISECOND, temp.get(Calendar.MILLISECOND)); } return cal; }
From source file:Main.java
public static void moveToCalendarSecond(Calendar cal, int second) { assertArgumentNotMinusInteger("second", second); cal.set(Calendar.SECOND, second); }