List of usage examples for org.joda.time DateTime toCalendar
public Calendar toCalendar(Locale locale)
java.util.Calendar
, assigning exactly the same millisecond instant. From source file:org.joda.example.time.Examples.java
License:Apache License
private void runDateTime() { System.out.println("DateTime"); System.out.println("======="); System.out.println(//from w w w. j ava 2 s . c o m "DateTime stores a the date and time using millisecs from 1970-01-01T00:00:00Z internally"); System.out.println("DateTime is immutable and thread-safe"); System.out.println(" in = new DateTime()"); DateTime in = new DateTime(); System.out.println("Millisecond time: in.getMillis(): " + in.getMillis()); System.out.println("ISO string version: in.toString(): " + in.toString()); System.out.println("ISO chronology: in.getChronology(): " + in.getChronology()); System.out.println("Your time zone: in.getDateTimeZone(): " + in.getZone()); System.out.println("Change millis: in.withMillis(0): " + in.withMillis(0L)); System.out.println(""); System.out.println("Get year: in.getYear(): " + in.getYear()); System.out.println("Get monthOfYear: in.getMonthOfYear(): " + in.getMonthOfYear()); System.out.println("Get dayOfMonth: in.getDayOfMonth(): " + in.getDayOfMonth()); System.out.println("..."); System.out.println("Property access: in.dayOfWeek().get(): " + in.dayOfWeek().get()); System.out.println( "Day of week as text: in.dayOfWeek().getAsText(): " + in.dayOfWeek().getAsText()); System.out.println( "Day as short text: in.dayOfWeek().getAsShortText(): " + in.dayOfWeek().getAsShortText()); System.out.println("Day in french: in.dayOfWeek().getAsText(Locale.FRENCH):" + in.dayOfWeek().getAsText(Locale.FRENCH)); System.out.println("Max allowed value: in.dayOfWeek().getMaximumValue(): " + in.dayOfWeek().getMaximumValue()); System.out.println("Min allowed value: in.dayOfWeek().getMinimumValue(): " + in.dayOfWeek().getMinimumValue()); System.out.println( "Copy & set to Jan: in.monthOfYear().setCopy(1): " + in.monthOfYear().setCopy(1)); System.out.println( "Copy & add 14 months: in.monthOfYear().addCopy(14): " + in.monthOfYear().addToCopy(14)); System.out.println("Add 14 mnths in field:in.monthOfYear().addWrapFieldCopy(14): " + in.monthOfYear().addWrapFieldToCopy(14)); System.out.println("..."); System.out.println("Convert to Instant: in.toInstant(): " + in.toInstant()); System.out.println("Convert to DateTime: in.toDateTime(): " + in.toDateTime()); System.out.println("Convert to MutableDT: in.toMutableDateTime(): " + in.toMutableDateTime()); System.out.println("Convert to Date: in.toDate(): " + in.toDate()); System.out.println("Convert to Calendar: in.toCalendar(Locale.UK): " + in.toCalendar(Locale.UK).toString().substring(0, 46)); System.out.println("Convert to GregCal: in.toGregorianCalendar(): " + in.toGregorianCalendar().toString().substring(0, 46)); System.out.println(""); System.out.println(" in2 = new DateTime(in.getMillis() + 10)"); DateTime in2 = new DateTime(in.getMillis() + 10); System.out.println("Equals ms and chrono: in.equals(in2): " + in.equals(in2)); System.out.println("Compare millisecond: in.compareTo(in2): " + in.compareTo(in2)); System.out.println("Compare millisecond: in.isEqual(in2): " + in.isEqual(in2)); System.out.println("Compare millisecond: in.isAfter(in2): " + in.isAfter(in2)); System.out.println("Compare millisecond: in.isBefore(in2): " + in.isBefore(in2)); }
From source file:org.mifos.framework.util.helpers.DateUtils.java
License:Open Source License
public static String getLocalDateString(DateTime date, Locale locale) throws InvalidDateException { // the following line is for 1.1 release and will be removed when date // is localized locale = internalLocale;//from w w w . j a va2 s .c o m Calendar calendar = date.toCalendar(locale); java.sql.Date currentDate = new java.sql.Date(calendar.getTimeInMillis()); SimpleDateFormat format = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, locale); String userfmt = convertToCurrentDateFormat(format.toPattern()); return convertDbToUserFmt(currentDate.toString(), userfmt); }
From source file:org.modeshape.jdbc.rest.PropertyDefinition.java
License:Apache License
protected static Calendar parseDate(String dateString) throws IllegalArgumentException { DateTime result = new DateTime(dateString); return result.toCalendar(null); }
From source file:org.modeshape.web.jcr.rest.client.domain.PropertyDefinition.java
License:Apache License
public static Calendar parseDate(String dateString) throws IllegalArgumentException { DateTime result = new DateTime(dateString); return result.toCalendar(null); }
From source file:org.n52.oxf.ses.adapter.SESRequestBuilder_00.java
License:Open Source License
private Calendar createTerminationTime(String stringTime) { DateTime date = new DateTime(stringTime); DateTime now = new DateTime(); if (date.isAfter(now)) { return date.toCalendar(Locale.getDefault()); }/*from w w w . j ava 2 s . co m*/ /* * default to one month from now */ return now.plusMonths(1).toCalendar(Locale.getDefault()); }
From source file:org.n52.sos.ext.deleteobservation.DeleteObservationEncoder.java
License:Open Source License
@Override protected XmlObject create(DeleteObservationResponse dor) throws OwsExceptionReport { if (dor == null) { throw new UnsupportedEncoderInputException(this, dor); }// www . ja v a 2 s.co m final CompositeOwsException exceptions = new CompositeOwsException(); if (dor.getService() == null) { exceptions.add(new MissingServiceParameterException()); } if (dor.getVersion() == null) { exceptions.add(new MissingVersionParameterException()); } if (dor.getProcedureIdentifier() == null || dor.getProcedureIdentifier().isEmpty()) { exceptions.add(new MissingParameterValueException(DeleteObservationConstants.PROCEDURE_PARAM)); } if (dor.getObservableProperty() == null || dor.getObservableProperty().isEmpty()) { exceptions.add(new MissingParameterValueException(DeleteObservationConstants.OBSERVABLE_PARAM)); } if (dor.getResultTime() == null) { exceptions.add(new MissingParameterValueException(DeleteObservationConstants.RESULT_TIME_PARAM)); } exceptions.throwIfNotEmpty(); String procedureIdentifier = dor.getProcedureIdentifier(); String observableProperty = dor.getObservableProperty(); DateTime resultTime = dor.getResultTime(); DeleteObservationResponseDocument xbDeleteObsDoc = DeleteObservationResponseDocument.Factory .newInstance(getXmlOptions()); DeleteObservationResponseType xbDeleteObservationResponse = xbDeleteObsDoc .addNewDeleteObservationResponse(); xbDeleteObservationResponse.setProcedureIdentifier(procedureIdentifier); xbDeleteObservationResponse.setObservableProperty(observableProperty); xbDeleteObservationResponse.setResultTime(resultTime.toCalendar(null)); return xbDeleteObsDoc; }