List of usage examples for java.util GregorianCalendar getTime
public final Date getTime()
Date
object representing this Calendar
's time value (millisecond offset from the Epoch"). From source file:DateUtils.java
public static String[] getDateRange(int cmd) { GregorianCalendar gc = new GregorianCalendar(); GregorianCalendar gc2 = new GregorianCalendar(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); //$NON-NLS-1$ String ret[] = new String[2]; ret[1] = sdf.format(gc.getTime()); if (cmd == LAST_WEEK) { for (int i = 0; i < 7; i++) { gc2.add(Calendar.DATE, -1); }//from w ww .j av a 2s. c o m } if (cmd == LAST_MONTH) { gc2.add(Calendar.MONTH, -1); } ret[0] = sdf.format(gc2.getTime()); return ret; }
From source file:com.microsoftopentechnologies.azchat.web.common.utils.AzureChatStorageUtils.java
/** * This method will assign private access to the blob container. * /* ww w . ja v a2 s . com*/ * @param container * @return * @throws Exception */ public static String generateSASURL(CloudBlobContainer container) throws Exception { LOGGER.info("[AzureChatStorageUtils][assignPrivateAccess] start"); String signature = AzureChatConstants.CONSTANT_EMPTY_STRING; SharedAccessBlobPolicy sharedAccessBlobPolicy = new SharedAccessBlobPolicy(); GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone(AzureChatConstants.TIMEZONE_UTC)); calendar.setTime(new Date()); sharedAccessBlobPolicy.setSharedAccessStartTime(calendar.getTime()); calendar.add(Calendar.HOUR, 23); sharedAccessBlobPolicy.setSharedAccessExpiryTime(calendar.getTime()); sharedAccessBlobPolicy.setPermissions(EnumSet.of(SharedAccessBlobPermissions.READ)); BlobContainerPermissions containerPermissions = new BlobContainerPermissions(); container.uploadPermissions(containerPermissions); LOGGER.debug("Private Access Permissions uploaded Successfully."); signature = container.generateSharedAccessSignature(sharedAccessBlobPolicy, null); LOGGER.info("[AzureChatStorageUtils][assignPrivateAccess] end"); return signature; }
From source file:org.openvpms.web.workspace.workflow.scheduling.SchedulingHelper.java
/** * Returns the time of the slot closest to that of the specified time. * * @param time the time//ww w.j av a 2 s.c o m * @param slotSize the size of the slot, in minutes * @param roundUp if {@code true} round up to the nearest slot, otherwise round down * @return the nearest slot time to {@code time} */ public static Date getSlotTime(Date time, int slotSize, boolean roundUp) { Date result; int mins = getMinutes(time); int nearestSlot = getNearestSlot(mins, slotSize); if (nearestSlot != mins) { if (roundUp) { nearestSlot += slotSize; } GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime(time); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.add(Calendar.MINUTE, nearestSlot); result = calendar.getTime(); } else { result = time; } return result; }
From source file:DateUtility.java
/** * This will retun the first millisecond of the month * that contains the timestamp provided/*from www .j av a2 s . c om*/ * @param timestamp * @return long */ static public long getFirstMilliOfMonth(long timestamp, TimeZone tz) { GregorianCalendar cal = new GregorianCalendar(); cal.setTimeZone(tz); cal.setTime(new Date(timestamp)); cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Date date = cal.getTime(); return date.getTime(); }
From source file:DateUtil.java
/** * Roll the java.util.Time forward or backward. * @param startDate - The start date// www. j a v a2 s . co m * @period Calendar.YEAR etc * @param amount - Negative to rollbackwards. */ public static java.sql.Time rollTime(java.util.Date startDate, int period, int amount) { GregorianCalendar gc = new GregorianCalendar(); gc.setTime(startDate); gc.add(period, amount); return new java.sql.Time(gc.getTime().getTime()); }
From source file:DateUtil.java
/** * Roll the java.sql.Date forward or backward. * @param startDate - The start date/*from www .j a va2 s .co m*/ * @period Calendar.YEAR etc * @param amount - Negative to rollbackwards. */ public static java.sql.Date rollDate(java.util.Date startDate, int period, int amount) { GregorianCalendar gc = new GregorianCalendar(); gc.setTime(startDate); gc.add(period, amount); return new java.sql.Date(gc.getTime().getTime()); }
From source file:org.vanbest.xmltv.ZiggoGids.java
public static URL programmeUrl(Channel channel, int day, int hour, int period) throws Exception { StringBuilder s = new StringBuilder(epg_data_root); s.append("?channelIDs="); s.append(channel.id);//from w w w. j a v a 2 s . c o m GregorianCalendar cal = new GregorianCalendar(); cal.add(Calendar.DAY_OF_MONTH, day); cal.set(Calendar.HOUR_OF_DAY, hour); cal.set(Calendar.MINUTE, 0); String date = new SimpleDateFormat("yyyy-MM-dd+HH").format(cal.getTime()); s.append("&date=" + date); s.append("&period=" + period); return new URL(s.toString()); }
From source file:DateUtil.java
/** * Roll the java.util.Date forward or backward. * @param startDate - The start date/*from w w w . ja va2 s .co m*/ * @period Calendar.YEAR etc * @param amount - Negative to rollbackwards. */ public static java.util.Date rollDateTime(java.util.Date startDate, int period, int amount) { GregorianCalendar gc = new GregorianCalendar(); gc.setTime(startDate); gc.add(period, amount); return new java.util.Date(gc.getTime().getTime()); }
From source file:com.microsoft.windowsazure.mobileservices.zumoe2etestapp.framework.Util.java
public static Date getUTCDate(int year, int month, int day, int hour, int minute, int second) { GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("utc")); int dateMonth = month - 1; calendar.set(year, dateMonth, day, hour, minute, second); calendar.set(Calendar.MILLISECOND, 0); return calendar.getTime(); }
From source file:HSSFDateUtil.java
/** * Given an Excel date with either 1900 or 1904 date windowing, converts it to * a java.util.Date./* ww w . j a v a 2 s. c om*/ * * NOTE: If the default <code>TimeZone</code> in Java uses Daylight Saving * Time then the conversion back to an Excel date may not give the same value, * that is the comparison <CODE>excelDate == * getExcelDate(getJavaDate(excelDate,false))</CODE> is not always true. For * example if default timezone is <code>Europe/Copenhagen</code>, on * 2004-03-28 the minute after 01:59 CET is 03:00 CEST, if the excel date * represents a time between 02:00 and 03:00 then it is converted to past * 03:00 summer time * * @param date * The Excel date. * @param use1904windowing * true if date uses 1904 windowing, or false if using 1900 date * windowing. * @return Java representation of the date, or null if date is not a valid * Excel date * @see java.util.TimeZone */ public static Date getJavaDate(final double date, final boolean use1904windowing) { if (isValidExcelDate(date)) { int startYear = 1900; int dayAdjust = -1; // Excel thinks 2/29/1900 is a valid date, which it // isn't final int wholeDays = (int) Math.floor(date); if (use1904windowing) { startYear = 1904; dayAdjust = 1; // 1904 date windowing uses 1/2/1904 as the first day } else if (wholeDays < 61) { // Date is prior to 3/1/1900, so adjust because Excel thinks 2/29/1900 // exists // If Excel date == 2/29/1900, will become 3/1/1900 in Java // representation dayAdjust = 0; } final GregorianCalendar calendar = new GregorianCalendar(startYear, 0, wholeDays + dayAdjust); final int millisecondsInDay = (int) ((date - Math.floor(date)) * (double) DAY_MILLISECONDS + 0.5); calendar.set(GregorianCalendar.MILLISECOND, millisecondsInDay); return calendar.getTime(); } else { return null; } }