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:Main.java
@SuppressWarnings("deprecation") public static String changeDateAsMonth(String date, int imonth) { GregorianCalendar calendar = new GregorianCalendar(); if (date.length() == 8) { calendar.set(Integer.parseInt(date.substring(0, 4)), Integer.parseInt(date.substring(4, 6)) - 1, Integer.parseInt(date.substring(6, 8))); } else if (date.length() == 10) { calendar.set(Integer.parseInt(date.substring(0, 4)), Integer.parseInt(date.substring(5, 7)) - 1, Integer.parseInt(date.substring(8, 10))); }// w ww. j a v a2 s .co m calendar.add(GregorianCalendar.MONTH, imonth); String sDate[] = calendar.getTime().toLocaleString().split(" "); return sDate[0]; }
From source file:CalendarUtils.java
/** * See the other round method. Works with a Date object. */// w w w .j a v a2s . c o m public static Date round(Date val, int field) { GregorianCalendar gval = new GregorianCalendar(); gval.setTime(val); modify(gval, field, true); return gval.getTime(); }
From source file:CalendarUtils.java
/** * See the other trunc method. Works with a Date. *///from ww w .j av a 2 s . c o m public static Date trunc(Date val, int field) { GregorianCalendar gval = new GregorianCalendar(); gval.setTime(val); modify(gval, field, false); return gval.getTime(); }
From source file:com.hybridbpm.core.util.HybridbpmCoreUtil.java
public static Date toDate(LocalDateTime ldt) { ZonedDateTime zdt = ZonedDateTime.of(ldt, ZoneId.systemDefault()); GregorianCalendar cal = GregorianCalendar.from(zdt); return cal.getTime(); }
From source file:org.energyos.espi.common.test.EspiFactory.java
public static GregorianCalendar newCalendar(int year, int month, int date) { GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("GMT+00:00")); calendar.set(year, month, date, 0, 0, 0); calendar.set(Calendar.MILLISECOND, 0); calendar.getTime(); return calendar; }
From source file:oscar.MyDateFormat.java
public static java.sql.Date getSysDate(String pDate) { pDate = StringUtils.trimToNull(pDate); if (pDate == null) return null; if ("TODAY".equals(pDate.toUpperCase())) return new java.sql.Date(new Date().getTime()); try {/*w ww .jav a 2 s . c om*/ char sep = '-'; boolean bnosep = false; int idx = pDate.indexOf(sep); if (idx < 0) { sep = '/'; idx = pDate.indexOf(sep); } bnosep = idx < 0; int day, month, year; if (bnosep) { year = Integer.parseInt(pDate.substring(0, 4)); month = Integer.parseInt(pDate.substring(4, 6)); day = Integer.parseInt(pDate.substring(6, 8)); } else { year = Integer.parseInt(pDate.substring(0, idx)); int idx1 = pDate.indexOf(sep, idx + 1); month = Integer.parseInt(pDate.substring(idx + 1, idx1)); idx = idx1; idx1 = pDate.indexOf(' '); if (idx1 < 0) idx1 = pDate.length(); day = Integer.parseInt(pDate.substring(idx + 1, idx1)); } if (month > 0) { month = month - 1; } GregorianCalendar cal = new GregorianCalendar(year, month, day, 0, 0, 0); return new java.sql.Date(cal.getTime().getTime()); } catch (Exception e) { MiscUtils.getLogger().debug("Invalid Date - the input date is in wrong format or out of range"); return null; } }
From source file:org.oscarehr.web.MisReportUIBean.java
public static String getDateRangeForDisplay(GregorianCalendar startDate, GregorianCalendar endDate) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); return (StringEscapeUtils.escapeHtml(simpleDateFormat.format(startDate.getTime()) + " to " + simpleDateFormat.format(endDate.getTime()) + " (inclusive)")); }
From source file:com.fluidops.iwb.api.ValueResolver.java
/** * Convert a timestamp like 182843848 to a human-readable date. * //www .j a v a2 s . c o m * @param value * @return */ private static String resolveDateFromTimestamp(String value, long multiplyToMs) { Long t = Long.valueOf(value) * multiplyToMs; GregorianCalendar c = new GregorianCalendar(); c.setTimeInMillis(t); DateFormat df = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss"); return df.format(c.getTime()); }
From source file:DateUtility.java
/** * Gets the last millsecond of the month, according to the timestamp and * timezone arguments.//w w w . j a v a2 s. com * @param timestamp * @param tz * @return long */ static public long getLastMilliOfMonth(long timestamp, TimeZone tz) { timestamp = getFirstMilliOfMonth(timestamp, tz); GregorianCalendar cal = new GregorianCalendar(); cal.setTimeZone(tz); cal.setTime(new Date(timestamp)); // now we'll roll the calendar forward one month. // in the case of december, we need to roll forward the year too if (cal.get(GregorianCalendar.MONTH) == GregorianCalendar.DECEMBER) { cal.roll(GregorianCalendar.YEAR, true); } cal.roll(GregorianCalendar.MONTH, true); long date = cal.getTime().getTime(); date = date - 1L; return date; }
From source file:com.thed.zephyr.jenkins.utils.rest.Cycle.java
public static Long createCycle(ZephyrConfigModel zephyrData) { Long cycleId = 0L;//from w w w. j ava 2 s. c o m HttpResponse response = null; try { String createCycleURL = URL_CREATE_CYCLES.replace("{SERVER}", zephyrData.getRestClient().getUrl()); Date date = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("E dd, yyyy hh:mm a"); String dateFormatForCycleCreation = sdf.format(date); JSONObject jObject = new JSONObject(); String cycleName = zephyrData.getCyclePrefix() + dateFormatForCycleCreation; SimpleDateFormat sdf1 = new SimpleDateFormat("dd/MMM/yy"); String startDate = sdf1.format(date); GregorianCalendar gCal = new GregorianCalendar(); if (zephyrData.getCycleDuration().trim().equalsIgnoreCase("30 days")) { gCal.add(Calendar.DAY_OF_MONTH, +29); } else if (zephyrData.getCycleDuration().trim().equalsIgnoreCase("7 days")) { gCal.add(Calendar.DAY_OF_MONTH, +6); } String endDate = sdf1.format(gCal.getTime()); jObject.put("name", cycleName); jObject.put("projectId", zephyrData.getZephyrProjectId()); jObject.put("versionId", zephyrData.getVersionId()); jObject.put("startDate", startDate); jObject.put("endDate", endDate); StringEntity se = new StringEntity(jObject.toString(), "utf-8"); HttpPost createCycleRequest = new HttpPost(createCycleURL); createCycleRequest.setHeader("Content-Type", "application/json"); createCycleRequest.setEntity(se); response = zephyrData.getRestClient().getHttpclient().execute(createCycleRequest, zephyrData.getRestClient().getContext()); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } int statusCode = response.getStatusLine().getStatusCode(); if (statusCode >= 200 && statusCode < 300) { HttpEntity entity = response.getEntity(); String string = null; try { string = EntityUtils.toString(entity); } catch (ParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } try { JSONObject cycleObj = new JSONObject(string); cycleId = cycleObj.getLong("id"); } catch (JSONException e) { e.printStackTrace(); } } else if (statusCode == 405) { try { throw new ClientProtocolException("ZAPI plugin license is invalid" + statusCode); } catch (ClientProtocolException e) { e.printStackTrace(); } } else { try { throw new ClientProtocolException("Unexpected response status: " + statusCode); } catch (ClientProtocolException e) { e.printStackTrace(); } } return cycleId; }