List of usage examples for java.text SimpleDateFormat setCalendar
public void setCalendar(Calendar newCalendar)
From source file:org.sakaiproject.component.section.sakai.CourseSectionImpl.java
public static final String convertTimeToString(Time time) { if (time == null) { return null; }/* w w w . ja v a 2s . c o m*/ SimpleDateFormat sdf = new SimpleDateFormat(CourseSectionImpl.TIME_FORMAT_DATE_TZ); // Time zone from user TimeZone userTz = timeService.getLocalTimeZone(); sdf.setTimeZone(userTz); // Today at 0.00 Calendar date = new GregorianCalendar(userTz); date.set(Calendar.HOUR_OF_DAY, 0); date.set(Calendar.MINUTE, 0); // Add the RawOffset of server, to write REAL TIME in STRING detached from server date.setTimeInMillis(date.getTimeInMillis() + time.getTime() + TimeZone.getDefault().getRawOffset()); sdf.setCalendar(date); return sdf.format(date.getTime()); }
From source file:org.dspace.search.DSIndexer.java
/** * Helper function to retrieve a date using a best guess of the potential date encodings on a field * //from www. jav a2 s. co m * @param t * @return */ private static Date toDate(String t) { SimpleDateFormat[] dfArr; // Choose the likely date formats based on string length switch (t.length()) { case 4: dfArr = new SimpleDateFormat[] { new SimpleDateFormat("yyyy") }; break; case 6: dfArr = new SimpleDateFormat[] { new SimpleDateFormat("yyyyMM") }; break; case 7: dfArr = new SimpleDateFormat[] { new SimpleDateFormat("yyyy-MM") }; break; case 8: dfArr = new SimpleDateFormat[] { new SimpleDateFormat("yyyyMMdd"), new SimpleDateFormat("yyyy MMM") }; break; case 10: dfArr = new SimpleDateFormat[] { new SimpleDateFormat("yyyy-MM-dd") }; break; case 11: dfArr = new SimpleDateFormat[] { new SimpleDateFormat("yyyy MMM dd") }; break; case 20: dfArr = new SimpleDateFormat[] { new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'") }; break; default: dfArr = new SimpleDateFormat[] { new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") }; break; } for (SimpleDateFormat df : dfArr) { try { // Parse the date df.setCalendar(Calendar.getInstance(TimeZone.getTimeZone("UTC"))); df.setLenient(false); return df.parse(t); } catch (ParseException pe) { log.error("Unable to parse date format", pe); } } return null; }
From source file:io.github.proxyprint.kitchen.models.printshops.RegisterRequest.java
/** * From GregoriaCalendar to String./*from w w w .ja v a 2s .com*/ * * @param c, GregorianCalendar instance * @return Well formated string for display */ private String GregorianCalendarToString(GregorianCalendar c) { SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm"); sdf.setCalendar(c); String dateFormatted = sdf.format(c.getTime()); return dateFormatted; }
From source file:org.apache.roller.weblogger.ui.core.tags.calendar.WeblogCalendarModel.java
public void setDay(String month) throws Exception { SimpleDateFormat fmt = DateUtil.get8charDateFormat(); fmt.setCalendar(getCalendar()); ParsePosition pos = new ParsePosition(0); initDay(fmt.parse(month, pos));//from w w w .j a va 2s . co m }
From source file:com.surevine.alfresco.webscript.gsa.getallitems.GetAllItemsCommandWebscriptImpl.java
public StringBuilder createXMLForSearchResult(SearchResult result) { //Format the date for XML output SimpleDateFormat sdf = new SimpleDateFormat(ISO8601LocalFormat); sdf.setCalendar(Calendar.getInstance(GMT)); String formattedDate = sdf.format(result.getLastModifiedDate()); //Write the results as XML StringBuilder sb = new StringBuilder(1000); sb.append("<result>"); sb.append("<nodeRef>").append(StringEscapeUtils.escapeXml(result.getNodeRef().toString())) .append("</nodeRef>"); sb.append("<modifiedDateTime>").append(StringEscapeUtils.escapeXml(formattedDate)) .append("</modifiedDateTime>"); if (result.getDocumentType() != null) { sb.append("<documentType>").append(StringEscapeUtils.escapeXml(result.getDocumentType().toString())) .append("</documentType>"); }/*from ww w . j av a 2 s .c o m*/ if (result.getModifiedBy() != null) { sb.append("<modifiedBy>").append(StringEscapeUtils.escapeXml(result.getModifiedBy())) .append("</modifiedBy>"); } sb.append("<title>").append(StringEscapeUtils.escapeXml(result.getTitle())).append("</title>"); sb.append("<url>").append(StringEscapeUtils.escapeXml(result.getURL())).append("</url>"); sb.append("<mimetype>").append(StringEscapeUtils.escapeXml(result.getMimeType())).append("</mimetype>"); sb.append("<content>").append(result.getContent()).append("</content>"); //Base64 encoded so don't need to escape sb.append(createXMLForSecurityLabel(result.getSecurityLabel())); sb.append("</result>"); return sb; }
From source file:com.surevine.alfresco.webscript.gsa.getallitems.GetAllItemsCommandImpl.java
/** * Given a date, return the date as a String *///from ww w . jav a 2 s .co m protected String DateToLuceneDateString(Date date) { SimpleDateFormat sdf = new SimpleDateFormat(LUCENE_DATE_FORMAT); sdf.setCalendar(Calendar.getInstance(GMT)); return sdf.format(date); }
From source file:org.apache.roller.weblogger.ui.rendering.pagers.AbstractWeblogEntriesPager.java
/** * Parse data as either 6-char or 8-char format. *///w ww . ja v a2 s . c om protected Date parseDate(String dateString) { Date ret = null; SimpleDateFormat char8DateFormat = DateUtil.get8charDateFormat(); SimpleDateFormat char6DateFormat = DateUtil.get6charDateFormat(); Calendar cal = Calendar.getInstance(weblog.getTimeZoneInstance(), weblog.getLocaleInstance()); if (dateString != null && dateString.length() == 8 && StringUtils.isNumeric(dateString)) { char8DateFormat.setCalendar(cal); ParsePosition pos = new ParsePosition(0); ret = char8DateFormat.parse(dateString, pos); // make sure the requested date is not in the future Date today = getToday(); if (ret.after(today)) ret = today; } if (dateString != null && dateString.length() == 6 && StringUtils.isNumeric(dateString)) { char6DateFormat.setCalendar(cal); ParsePosition pos = new ParsePosition(0); ret = char6DateFormat.parse(dateString, pos); // make sure the requested date is not in the future Date today = getToday(); if (ret.after(today)) ret = today; } return ret; }
From source file:com.mirth.connect.client.ui.components.MirthTreeTable.java
public void setMirthTransferHandlerEnabled(boolean enable) { setDragEnabled(enable);//from ww w. jav a 2 s. co m if (transferHandler == null) { transferHandler = new TransferHandler() { @Override public int getSourceActions(JComponent c) { return COPY_OR_MOVE; } @Override protected Transferable createTransferable(JComponent c) { int row = getSelectedRow(); List columnValuesList = new ArrayList<Object>(); for (TableColumn column : getColumns()) { Object value = getValueAt(row, convertColumnIndexToView(column.getModelIndex())); if (value != null) { if (value instanceof Calendar) { Calendar calendar = (GregorianCalendar) value; SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT); dateFormat.setCalendar(calendar); value = (String) dateFormat.format(calendar.getTime()); } else if (value instanceof Long) { value = String.valueOf(value); } else if (value instanceof Status) { value = Status.fromChar(((Status) value).getStatusCode()); } else { value = String.valueOf(value); } } else { value = "-"; } columnValuesList.add(value); } return new StringSelection(StringUtils.join(columnValuesList, " ")); } }; setTransferHandler(transferHandler); } }
From source file:org.dasein.cloud.aws.storage.S3Method.java
private String getDate() throws CloudException { if (provider.getEC2Provider().isStorage() && "google".equalsIgnoreCase(provider.getProviderName())) { SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ssz", new Locale("US")); Calendar cal = Calendar.getInstance(new SimpleTimeZone(0, "GMT")); format.setCalendar(cal);/* w w w . java 2s . co m*/ return format.format(new Date()); } else { SimpleDateFormat fmt = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z"); Calendar cal = Calendar.getInstance(new SimpleTimeZone(0, "GMT")); fmt.setCalendar(cal); return fmt.format(new Date()); } }
From source file:carsharing.starter.automotive.iot.ibm.com.mobilestarterapp.AnalyzeMyDriving.java
public void sendLocation(final Location location) { if (connectDeviceClient()) { final GregorianCalendar cal = new GregorianCalendar(); final TimeZone gmt = TimeZone.getTimeZone("GMT"); cal.setTimeZone(gmt);/*w w w. j a v a 2 s . com*/ final SimpleDateFormat formattedCal = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); formattedCal.setCalendar(cal); final String timestamp = formattedCal.format(cal.getTime()); final double speed = Math.max(0.0, location.getSpeed() * 60 * 60 / 1000); final double longitude = location.getLongitude(); final double latitude = location.getLatitude(); final String mobileAppDeviceId = FirstPage.mobileAppDeviceId; final String status = tripID != null ? "Unlocked" : "Locked"; if (tripID == null) { // this trip should be completed, so lock device now userUnlocked = false; } final JsonObject event = new JsonObject(); final JsonObject data = new JsonObject(); event.add("d", data); data.addProperty("trip_id", tripID); data.addProperty("speed", speed); data.addProperty("lng", longitude); data.addProperty("lat", latitude); data.addProperty("ts", timestamp); data.addProperty("id", mobileAppDeviceId); data.addProperty("status", status); final ActionBar supportActionBar = ((AppCompatActivity) getActivity()).getSupportActionBar(); if (deviceClient.publishEvent("sensorData", event, 0)) { Log.d("MQTT", "publish event " + event.toString()); supportActionBar.setTitle(speedMessage + " - Data sent (" + (++transmissionCount) + ")"); } else { Log.d("MQTT", "ERROR in publishing event " + event.toString()); supportActionBar.setTitle("Data Transmission Error."); } } }