List of usage examples for java.util GregorianCalendar setTime
public final void setTime(Date date)
Date
. From source file:org.codice.ddf.spatial.ogc.csw.catalog.converter.CswMarshallHelper.java
static void writeValue(HierarchicalStreamWriter writer, MarshallingContext context, AttributeDescriptor attributeDescriptor, QName field, Serializable value) { String xmlValue = null;//from www.ja va 2 s . c o m AttributeType.AttributeFormat attrFormat = null; if (attributeDescriptor != null && attributeDescriptor.getType() != null) { attrFormat = attributeDescriptor.getType().getAttributeFormat(); } if (attrFormat == null) { attrFormat = AttributeType.AttributeFormat.STRING; } String name = null; if (!StringUtils.isBlank(field.getNamespaceURI())) { if (!StringUtils.isBlank(field.getPrefix())) { name = field.getPrefix() + CswConstants.NAMESPACE_DELIMITER + field.getLocalPart(); } else { name = field.getLocalPart(); } } else { name = field.getLocalPart(); } switch (attrFormat) { case BINARY: xmlValue = Base64.getEncoder().encodeToString((byte[]) value); break; case DATE: GregorianCalendar cal = new GregorianCalendar(); cal.setTime((Date) value); xmlValue = XSD_FACTORY.newXMLGregorianCalendar(cal).toXMLFormat(); break; case OBJECT: break; case GEOMETRY: case XML: default: xmlValue = value.toString(); break; } // Write the node if we were able to convert it. if (xmlValue != null) { writer.startNode(name); if (!StringUtils.isBlank(field.getNamespaceURI())) { if (StringUtils.isBlank(field.getPrefix())) { writer.addAttribute(XMLConstants.XMLNS_ATTRIBUTE, field.getNamespaceURI()); } } writer.setValue(xmlValue); writer.endNode(); } }
From source file:cz.zcu.kiv.eegdatabase.logic.pdf.ReservationPDF.java
public static PdfPTable formatReservation(Reservation reservation) { int padding = 5; GregorianCalendar created = new GregorianCalendar(); created.setTime(reservation.getCreationTime()); GregorianCalendar startTime = new GregorianCalendar(); startTime.setTime(reservation.getStartTime()); GregorianCalendar endTime = new GregorianCalendar(); endTime.setTime(reservation.getEndTime()); String personName = BookingRoomUtils.formatPersonName(reservation.getPerson()); Font title = FontFactory.getFont("Trebuchet MS", "utf-8", 15, Font.BOLD, new BaseColor(59, 70, 00)); Font header = FontFactory.getFont(FontFactory.TIMES_BOLD, 13, Font.BOLD, BaseColor.BLACK); Font value = FontFactory.getFont(FontFactory.TIMES, 13); PdfPTable table = new PdfPTable(2); PdfPCell cell;//w ww . j a v a 2 s . c om Phrase phrase; phrase = new Phrase("Reservation by " + personName); phrase.setFont(title); cell = new PdfPCell(phrase); cell.setColspan(2); cell.setBorder(0); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorderWidthTop(1); cell.setBorderWidthLeft(1); cell.setBorderWidthRight(1); cell.setPadding(padding); cell.setPaddingBottom(5); table.addCell(cell); phrase = new Phrase("Date: "); phrase.setFont(header); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); cell.setBorderWidthLeft(1); cell.setPadding(padding); table.addCell(cell); phrase = new Phrase(BookingRoomUtils.getDate(startTime)); phrase.setFont(value); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); cell.setBorderWidthRight(1); cell.setPadding(padding); table.addCell(cell); phrase = new Phrase("Start: "); phrase.setFont(header); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); cell.setBorderWidthLeft(1); cell.setPadding(padding); table.addCell(cell); phrase = new Phrase(BookingRoomUtils.getHoursAndMinutes(startTime)); phrase.setFont(value); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); cell.setBorderWidthRight(1); cell.setPadding(padding); table.addCell(cell); phrase = new Phrase("End: "); phrase.setFont(header); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); cell.setBorderWidthLeft(1); cell.setBorderWidthBottom(1); cell.setPadding(padding); table.addCell(cell); phrase = new Phrase(BookingRoomUtils.getHoursAndMinutes(endTime)); phrase.setFont(value); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); cell.setBorderWidthRight(1); cell.setBorderWidthBottom(1); cell.setPadding(padding); table.addCell(cell); table.setSpacingBefore(10); table.setSpacingAfter(10); return table; }
From source file:br.gov.frameworkdemoiselle.behave.integration.alm.objects.util.GenerateXMLString.java
public static String getExecutionresultString(String urlServer, String projectAreaAlias, String encoding, String executionWorkItemUrl, ScenarioState stateOf, Date _startDate, Date _endDate, String details) throws JAXBException, DatatypeConfigurationException { Date startDate = (Date) _startDate.clone(); Date endDate = (Date) _endDate.clone(); com.ibm.rqm.xml.bind.Executionresult.Executionworkitem workTest = new com.ibm.rqm.xml.bind.Executionresult.Executionworkitem(); workTest.setHref(executionWorkItemUrl); State state = new State(); Executionresult result = new Executionresult(); if (stateOf.equals(ScenarioState.FAILED)) { state.setContent("com.ibm.rqm.execution.common.state.failed"); } else {// w w w. jav a2 s .c om if (stateOf.equals(ScenarioState.PENDING)) { state.setContent("com.ibm.rqm.execution.common.state.blocked"); } else { state.setContent("com.ibm.rqm.execution.common.state.passed"); } } result.setState(state); result.setExecutionworkitem(workTest); // Datas de incio e fim do teste GregorianCalendar c = new GregorianCalendar(); c.setTime(startDate); XMLGregorianCalendar startDateXml = DatatypeFactory.newInstance().newXMLGregorianCalendar(c); result.setStarttime(startDateXml); c.setTime(endDate); XMLGregorianCalendar endDateXml = DatatypeFactory.newInstance().newXMLGregorianCalendar(c); result.setEndtime(endDateXml); // Details Details d = new Details(); d.getContent().add(details); result.setDetails(d); JAXBContext jaxb = JAXBContext.newInstance(Executionresult.class); Marshaller marshaller = jaxb.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.setProperty(Marshaller.JAXB_ENCODING, encoding); StringWriter resourceString = new StringWriter(); marshaller.marshal(result, resourceString); return resourceString.toString(); }
From source file:com.microsoftopentechnologies.azchat.web.common.utils.AzureChatStorageUtils.java
/** * This method will assign private access to the blob container. * /*from ww w . j a v a2s . c o m*/ * @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.archetype.rules.util.DateRules.java
/** * Adds a date and time.//www . j av a 2 s . co m * * @param date the date part * @param time the time to add * @return the date+time */ public static Date addDateTime(Date date, Date time) { GregorianCalendar dateCal = new GregorianCalendar(); dateCal.setTime(date); GregorianCalendar timeCal = new GregorianCalendar(); timeCal.setTime(time); dateCal.set(Calendar.HOUR_OF_DAY, timeCal.get(Calendar.HOUR_OF_DAY)); dateCal.set(Calendar.MINUTE, timeCal.get(Calendar.MINUTE)); dateCal.set(Calendar.SECOND, timeCal.get(Calendar.SECOND)); return dateCal.getTime(); }
From source file:org.openvpms.archetype.rules.util.DateRules.java
/** * Calculates a date given a start time, interval and the date units. * * @param startTime the start time// w ww .j a v a2 s. c o m * @param interval the time interval. May be negative to calculate a date in the past * @param units the interval units * @return the date */ public static Date getDate(Date startTime, int interval, DateUnits units) { GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime(startTime); if (units != null) { switch (units) { case YEARS: calendar.add(Calendar.YEAR, interval); break; case MONTHS: calendar.add(Calendar.MONTH, interval); break; case WEEKS: calendar.add(Calendar.DAY_OF_YEAR, interval * 7); break; case DAYS: calendar.add(Calendar.DAY_OF_YEAR, interval); break; case HOURS: calendar.add(Calendar.HOUR_OF_DAY, interval); break; case MINUTES: calendar.add(Calendar.MINUTE, interval); break; } } return calendar.getTime(); }
From source file:com.prowidesoftware.swift.model.mx.BusinessHeader.java
/** * Returns a gregorian calendar for current moment in UTC time zone * @return created calendar or null if DatatypeFactory fails to create the calendar instance *///from w ww . j a v a2 s . co m private static XMLGregorianCalendar now() { GregorianCalendar c = new GregorianCalendar(); c.setTime(Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTime()); XMLGregorianCalendar creationDate = null; try { /* * important: cannot create XMLGregorianCalendar directly from Calendar object, * specific format must be used for the unmarshalled XML to pass XSD validation. */ creationDate = DatatypeFactory.newInstance() .newXMLGregorianCalendar(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(c.getTime())); } catch (DatatypeConfigurationException e) { log.log(Level.WARNING, "error initializing header creation date", e); } return creationDate; }
From source file:DateUtil.java
/** * Roll the java.util.Time forward or backward. * @param startDate - The start date/*from w w w. j a v a 2 s .c om*/ * @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.util.Date forward or backward. * @param startDate - The start date//from w w w . j a 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:DateUtil.java
/** * Roll the java.sql.Date forward or backward. * @param startDate - The start date/*from w w w . j av a 2s .c o 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()); }