List of usage examples for java.util Date clone
public Object clone()
From source file:Main.java
public static void main(String[] args) { // create a date Date date = new Date(); // clone it to a second date Object date2 = date.clone(); // print the results System.out.println("Original Date:" + date.toString()); System.out.println("Cloned date :" + date2.toString()); }
From source file:Util.java
/** * Sets the time on the same day to 00:00:00.000 * * @param date//from ww w .j a v a 2 s .c o m * @return a new date */ @SuppressWarnings("deprecation") public static Date truncateTime(Date date) { Date newDate = (Date) date.clone(); newDate.setHours(0); newDate.setMinutes(0); newDate.setSeconds(0); newDate.setTime(newDate.getTime() - newDate.getTime() % 1000); //Millisekunden auf 0 return newDate; }
From source file:com.omnigon.aem.common.utils.PojoUtils.java
public static Date unsafeDate(Date date) { return date != null ? (Date) date.clone() : null; }
From source file:com.googlecode.commons.swing.util.DateUtils2.java
public static Date getStartOfMonth(Date month) { if (month == null) { return null; }/*ww w. j ava 2 s . c o m*/ Date start = (Date) month.clone(); start = DateUtils.truncate(start, Calendar.MONTH); return start; }
From source file:com.googlecode.commons.swing.util.DateUtils2.java
public static Date getEndOfMonth(Date month) { if (month == null) { return null; }/* w w w.j av a 2 s. c om*/ Date end = (Date) month.clone(); end = DateUtils.truncate(end, Calendar.MONTH); end = DateUtils.addMonths(end, 1); end = DateUtils.addMilliseconds(end, -1); return end; }
From source file:com.bjond.utilities.DateTimeUtils.java
/** * Clones a date passed as a parameter./*from w w w . ja v a 2 s . c o m*/ * * NOTE: if date is null then null is returned. * * @param date Valid non-null java.util.Date object * @return New date. Original is not altered. */ public static Date clone(final Date date) { return (null != date) ? (Date) date.clone() : null; }
From source file:fr.openwide.core.commons.util.CloneUtils.java
/** * Clne une date.//ww w . j a v a 2s .c o m * Cette mthode est null safe. * * @param date clner * @return clne de la date passe en paramtre */ public static Date clone(Date date) { if (date == null) { return null; } else { return (Date) date.clone(); } }
From source file:com.jdom.get.stuff.done.domain.DueWithinDatesFilterOption.java
public static DueWithinDatesFilterOption parse(String string) { final String stringWithoutPrefix = string.replaceAll(FILTER_PREFIX, ""); Date earliest = null; Date latest = null;/*from w ww . ja v a 2s . c o m*/ if (TODAY.equals(stringWithoutPrefix)) { earliest = DateUtil.getCurrentDateZeroingHoursAndBelow(); latest = (Date) earliest.clone(); } else if (TOMORROW.equals(stringWithoutPrefix)) { earliest = new Date(DateUtil.getCurrentDateZeroingHoursAndBelow().getTime() + Constants.MILLIS_PER_DAY); latest = (Date) earliest.clone(); } else if (THIS_WEEK.equals(stringWithoutPrefix)) { earliest = DateUtil.getCurrentDateZeroingHoursAndBelow(); latest = new Date(DateUtil.getCurrentDateZeroingHoursAndBelow().getTime() + Constants.MILLIS_PER_WEEK); } return new DueWithinDatesFilterOption(earliest, latest); }
From source file:net.kamhon.ieagle.util.DateUtil.java
/** * Not Consider time. Just compare date. * /*from w ww . ja v a 2s . c o m*/ * @param date * @param startDate * @param endDate * @return */ public static boolean isBetweenDate(Date date, Date startDate, Date endDate) { Date clonedDate = (Date) date.clone(); clonedDate = formatDateByTime(clonedDate, 0, 0, 0, 0); Date clonedStartDate = (Date) startDate.clone(); Date clonedEndDate = (Date) endDate.clone(); clonedStartDate = formatDateByTime(clonedStartDate, 0, 0, 0, 0); clonedEndDate = formatDateByTime(clonedEndDate, 23, 59, 59, 999); return (clonedDate.equals(clonedStartDate) || clonedDate.after(clonedStartDate)) && (clonedDate.equals(clonedEndDate) || clonedDate.before(clonedEndDate)); }
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 {//ww w. j a v a 2 s. co m 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(); }