List of usage examples for java.util Calendar setTime
public final void setTime(Date date)
Date
. From source file:com.wiiyaya.framework.common.utils.DateUtils.java
/** * 00:00:00//ww w .ja v a2s .c o m * * @param date * @return ?? */ public static Date setDayStart(final Date date) { final Calendar c = Calendar.getInstance(); c.setLenient(false); c.setTime(date); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); return c.getTime(); }
From source file:com.wiiyaya.framework.common.utils.DateUtils.java
/** * ?23:59:59/*from w w w. jav a 2 s .c o m*/ * @param date * @return ?? */ public static Date setDayEnd(final Date date) { final Calendar c = Calendar.getInstance(); c.setLenient(false); c.setTime(date); c.set(Calendar.HOUR_OF_DAY, 23); c.set(Calendar.MINUTE, 59); c.set(Calendar.SECOND, 59); return c.getTime(); }
From source file:Main.java
/** * @param date {@linkplain Date} to pull date information from * @return a new Calendar instance with the date set to the provided date. Time set to zero. *///w w w .j a va 2s . co m public static Calendar getInstance(@Nullable Date date) { Calendar calendar = Calendar.getInstance(); if (date != null) { calendar.setTime(date); } copyDateTo(calendar, calendar); return calendar; }
From source file:com.nabla.wapp.server.general.Util.java
public static Calendar dateToCalendar(final Date dt) { final Calendar ret = new GregorianCalendar(); ret.setTime(dt); return ret;/*from ww w . j av a 2s . c o m*/ }
From source file:Main.java
/** * Checks if two date objects are on the same day ignoring time. * * 28 Mar 2002 13:45 and 28 Mar 2002 06:01 would return true. * 28 Mar 2002 13:45 and 12 Mar 2002 13:45 would return false. * //from www .ja va 2s. c o m * * @param date1 the first date, not altered, not null * @param date2 the second date, not altered, not null * @return true if they represent the same day * @throws IllegalArgumentException if either date is <code>null</code> * @since 2.1 */ public static boolean isSameDay(Date date1, Date date2) { if (date1 == null || date2 == null) { throw new IllegalArgumentException("The date must not be null"); } Calendar cal1 = Calendar.getInstance(); cal1.setTime(date1); Calendar cal2 = Calendar.getInstance(); cal2.setTime(date2); return isSameDay(cal1, cal2); }
From source file:com.dhenton9000.selenium.generic.UtilMethods.java
public static String getPreviousDate(int daysAgo) { DateFormat newFormat = new SimpleDateFormat("MM/dd/yyyy"); newFormat.setLenient(true);/*from w w w . j a va2 s.c o m*/ Calendar cal = Calendar.getInstance(); cal.setTime(new java.util.Date()); cal.add(Calendar.DATE, -1 * daysAgo); return newFormat.format(cal.getTime()); }
From source file:com.brightcove.com.zartan.verifier.video.PlaysReportingVerifier.java
public static boolean isToday(Long uploadDate) { Calendar uploaded = Calendar.getInstance(); uploaded.setTime(new Date(uploadDate)); Calendar now = Calendar.getInstance(); now.setTime(new Date()); return (uploaded.get(Calendar.ERA) == now.get(Calendar.ERA) && uploaded.get(Calendar.YEAR) == now.get(Calendar.YEAR) && uploaded.get(Calendar.DAY_OF_YEAR) == now.get(Calendar.DAY_OF_YEAR)); }
From source file:com.github.abhinavmishra14.aws.util.AWSUtil.java
/** * Gets the expiry date.<br/>//from w w w .j ava 2s.c om * Expire by parameter takes input as Calendar.Month, Calendar.Hour, Calendar.Minute etc. * * @param expireBy the expire by * @param expireByValue the expire by value * @return the expiry date * @see Calendar */ public static Date getExpiryDate(final int expireBy, final int expireByValue) { final Date currentDate = new Date(); final Calendar cal = Calendar.getInstance(); cal.setTime(currentDate); cal.add(expireBy, expireByValue); return cal.getTime(); }
From source file:io.github.bluemarlin.util.BluemarlineUtil.java
public static Date getDateInThePast(int days) { Date dateNow = new Date(); Calendar cal = Calendar.getInstance(); cal.setTime(dateNow); cal.add(Calendar.DATE, -days); Date d = cal.getTime();//from ww w . j ava 2 s. co m return d; }
From source file:Main.java
public static Calendar getStringDateToCal(String date) { Calendar cal = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); try {//from www.j ava 2 s .c om cal.setTime(sdf.parse(date)); } catch (Exception e) { } return cal; }