org.joda.time.format.ISODateTimeFormat#dateTime ( )源码实例Demo

下面列出了org.joda.time.format.ISODateTimeFormat#dateTime ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: coming   文件: Time_18_GJChronology_s.java
/**
 * Gets a debugging toString.
 * 
 * @return a debugging string
 */
public String toString() {
    StringBuffer sb = new StringBuffer(60);
    sb.append("GJChronology");
    sb.append('[');
    sb.append(getZone().getID());
    
    if (iCutoverMillis != DEFAULT_CUTOVER.getMillis()) {
        sb.append(",cutover=");
        DateTimeFormatter printer;
        if (withUTC().dayOfYear().remainder(iCutoverMillis) == 0) {
            printer = ISODateTimeFormat.date();
        } else {
            printer = ISODateTimeFormat.dateTime();
        }
        printer.withChronology(withUTC()).printTo(sb, iCutoverMillis);
    }
    
    if (getMinimumDaysInFirstWeek() != 4) {
        sb.append(",mdfw=");
        sb.append(getMinimumDaysInFirstWeek());
    }
    sb.append(']');
    
    return sb.toString();
}
 
源代码2 项目: twiliochat-android   文件: DateFormatterTest.java
@Test
public void testGetDateFromISOString() {
    String inputDate = "2015-10-21T07:28:00.000Z";

    DateTimeFormatter isoFormatter = ISODateTimeFormat.dateTime();
    DateTime date = null;

    try {
        date = isoFormatter.parseDateTime(inputDate);
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    }

    DateTime outputDate = DateFormatter.getDateFromISOString(inputDate);

    assertEquals(outputDate, date);
}
 
源代码3 项目: coming   文件: Time_6_GJChronology_t.java
/**
 * Gets a debugging toString.
 * 
 * @return a debugging string
 */
public String toString() {
    StringBuffer sb = new StringBuffer(60);
    sb.append("GJChronology");
    sb.append('[');
    sb.append(getZone().getID());
    
    if (iCutoverMillis != DEFAULT_CUTOVER.getMillis()) {
        sb.append(",cutover=");
        DateTimeFormatter printer;
        if (withUTC().dayOfYear().remainder(iCutoverMillis) == 0) {
            printer = ISODateTimeFormat.date();
        } else {
            printer = ISODateTimeFormat.dateTime();
        }
        printer.withChronology(withUTC()).printTo(sb, iCutoverMillis);
    }
    
    if (getMinimumDaysInFirstWeek() != 4) {
        sb.append(",mdfw=");
        sb.append(getMinimumDaysInFirstWeek());
    }
    sb.append(']');
    
    return sb.toString();
}
 
源代码4 项目: dremio-oss   文件: FragmentHandler.java
void checkStateAndLogIfNecessary() {
  if (!fragmentStarted) {
    final DateTimeFormatter formatter = ISODateTimeFormat.dateTime();
    if (canceled.get()) {
      logger.warn("Received cancel request at {} for fragment {} that was never started",
        formatter.print(cancellationTime),
        QueryIdHelper.getQueryIdentifier(handle));
    }

    FragmentEvent event;
    while ((event = finishedReceivers.poll()) != null) {
      logger.warn("Received early fragment termination at {} for path {} {} -> {} for a fragment that was never started",
        formatter.print(event.time),
        QueryIdHelper.getQueryId(handle.getQueryId()),
        QueryIdHelper.getFragmentId(event.handle),
        QueryIdHelper.getFragmentId(handle)
      );
    }
  }
}
 
/**
 * Create a new {@code DateTimeFormatter} using this factory.
 * <p>If no specific pattern or style has been defined,
 * the supplied {@code fallbackFormatter} will be used.
 * @param fallbackFormatter the fall-back formatter to use
 * when no specific factory properties have been set
 * @return a new date time formatter
 */
public DateTimeFormatter createDateTimeFormatter(DateTimeFormatter fallbackFormatter) {
	DateTimeFormatter dateTimeFormatter = null;
	if (StringUtils.hasLength(this.pattern)) {
		dateTimeFormatter = DateTimeFormat.forPattern(this.pattern);
	}
	else if (this.iso != null && this.iso != ISO.NONE) {
		switch (this.iso) {
			case DATE:
				dateTimeFormatter = ISODateTimeFormat.date();
				break;
			case TIME:
				dateTimeFormatter = ISODateTimeFormat.time();
				break;
			case DATE_TIME:
				dateTimeFormatter = ISODateTimeFormat.dateTime();
				break;
			default:
				throw new IllegalStateException("Unsupported ISO format: " + this.iso);
		}
	}
	else if (StringUtils.hasLength(this.style)) {
		dateTimeFormatter = DateTimeFormat.forStyle(this.style);
	}

	if (dateTimeFormatter != null && this.timeZone != null) {
		dateTimeFormatter = dateTimeFormatter.withZone(DateTimeZone.forTimeZone(this.timeZone));
	}
	return (dateTimeFormatter != null ? dateTimeFormatter : fallbackFormatter);
}
 
/**
 * Create a new {@code DateTimeFormatter} using this factory.
 * <p>If no specific pattern or style has been defined,
 * the supplied {@code fallbackFormatter} will be used.
 * @param fallbackFormatter the fall-back formatter to use
 * when no specific factory properties have been set
 * @return a new date time formatter
 */
public DateTimeFormatter createDateTimeFormatter(DateTimeFormatter fallbackFormatter) {
	DateTimeFormatter dateTimeFormatter = null;
	if (StringUtils.hasLength(this.pattern)) {
		dateTimeFormatter = DateTimeFormat.forPattern(this.pattern);
	}
	else if (this.iso != null && this.iso != ISO.NONE) {
		switch (this.iso) {
			case DATE:
				dateTimeFormatter = ISODateTimeFormat.date();
				break;
			case TIME:
				dateTimeFormatter = ISODateTimeFormat.time();
				break;
			case DATE_TIME:
				dateTimeFormatter = ISODateTimeFormat.dateTime();
				break;
			default:
				throw new IllegalStateException("Unsupported ISO format: " + this.iso);
		}
	}
	else if (StringUtils.hasLength(this.style)) {
		dateTimeFormatter = DateTimeFormat.forStyle(this.style);
	}

	if (dateTimeFormatter != null && this.timeZone != null) {
		dateTimeFormatter = dateTimeFormatter.withZone(DateTimeZone.forTimeZone(this.timeZone));
	}
	return (dateTimeFormatter != null ? dateTimeFormatter : fallbackFormatter);
}
 
源代码7 项目: chipster   文件: StorageAdminAPI.java
public void onChipsterMessage(ChipsterMessage msg) {
	ParameterMessage resultMessage = (ParameterMessage) msg;

	String usernamesString =  resultMessage.getNamedParameter(ParameterMessage.PARAMETER_USERNAME_LIST);
	String namesString = resultMessage.getNamedParameter(ParameterMessage.PARAMETER_SESSION_NAME_LIST);
	String sizesString = resultMessage.getNamedParameter(ParameterMessage.PARAMETER_SIZE_LIST);
	String datesString = resultMessage.getNamedParameter(ParameterMessage.PARAMETER_DATE_LIST);
	String idsString = resultMessage.getNamedParameter(ParameterMessage.PARAMETER_SESSION_UUID_LIST);
	String quotaString = resultMessage.getNamedParameter(ParameterMessage.PARAMETER_QUOTA);
	String quotaWarningString = resultMessage.getNamedParameter(ParameterMessage.PARAMETER_QUOTA_WARNING);
	String storageUsageString = resultMessage.getNamedParameter(ParameterMessage.PARAMETER_SIZE);
	
	String[] usernames = Strings.splitUnlessEmpty(usernamesString, "\t");
	String[] names = Strings.splitUnlessEmpty(namesString, "\t");
	String[] sizes = Strings.splitUnlessEmpty(sizesString, "\t");
	String[] dates = Strings.splitUnlessEmpty(datesString, "\t");
	String[] ids = Strings.splitUnlessEmpty(idsString, "\t");
	
	DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTime();
	entries = new LinkedList<StorageEntry>();
	for (int i = 0; i < names.length; i++) {

		StorageEntry entry = new StorageEntry();
		entry.setDate(dateTimeFormatter.parseDateTime(dates[i]).toDate());
		entry.setUsername(usernames[i]);
		entry.setSize(Long.parseLong(sizes[i]));
		entry.setName(names[i]);
		entry.setID(ids[i]);
		entries.add(entry);
	}
	
	quota = Long.parseLong(quotaString);
	quotaWarning = Long.parseLong(quotaWarningString);
	storageUsage = Long.parseLong(storageUsageString);

	latch.countDown();
}
 
源代码8 项目: syslog4j   文件: StructuredSyslogServerEvent.java
public DateTimeFormatter getDateTimeFormatter() {
	if (dateTimeFormatter == null) {
		this.dateTimeFormatter = ISODateTimeFormat.dateTime();
	}
	
	return dateTimeFormatter;
}
 
源代码9 项目: lams   文件: DateTimeFormatterFactory.java
/**
 * Create a new {@code DateTimeFormatter} using this factory.
 * <p>If no specific pattern or style has been defined,
 * the supplied {@code fallbackFormatter} will be used.
 * @param fallbackFormatter the fall-back formatter to use when no specific
 * factory properties have been set (can be {@code null}).
 * @return a new date time formatter
 */
public DateTimeFormatter createDateTimeFormatter(DateTimeFormatter fallbackFormatter) {
	DateTimeFormatter dateTimeFormatter = null;
	if (StringUtils.hasLength(this.pattern)) {
		dateTimeFormatter = DateTimeFormat.forPattern(this.pattern);
	}
	else if (this.iso != null && this.iso != ISO.NONE) {
		switch (this.iso) {
			case DATE:
				dateTimeFormatter = ISODateTimeFormat.date();
				break;
			case TIME:
				dateTimeFormatter = ISODateTimeFormat.time();
				break;
			case DATE_TIME:
				dateTimeFormatter = ISODateTimeFormat.dateTime();
				break;
			case NONE:
				/* no-op */
				break;
			default:
				throw new IllegalStateException("Unsupported ISO format: " + this.iso);
		}
	}
	else if (StringUtils.hasLength(this.style)) {
		dateTimeFormatter = DateTimeFormat.forStyle(this.style);
	}

	if (dateTimeFormatter != null && this.timeZone != null) {
		dateTimeFormatter = dateTimeFormatter.withZone(DateTimeZone.forTimeZone(this.timeZone));
	}
	return (dateTimeFormatter != null ? dateTimeFormatter : fallbackFormatter);
}
 
源代码10 项目: amforeas   文件: AmforeasUtils.java
/**
 * Check if a string has the ISO date time format. Uses the ISODateTimeFormat.dateTime() from JodaTime
 * and returns a DateTime instance. The correct format is yyyy-MM-ddTHH:mm:ss.SSSZ
 * @param arg the string to check
 * @return a DateTime instance if the string is in the correct ISO format.
 */
public static DateTime isDateTime (final String arg) {
    if (arg == null)
        return null;
    DateTimeFormatter f = ISODateTimeFormat.dateTime();
    DateTime ret = null;
    try {
        ret = f.parseDateTime(arg);
    } catch (IllegalArgumentException e) {
        l.debug("{} is not a valid ISO DateTime", arg);
    }
    return ret;
}
 
源代码11 项目: amforeas   文件: UtilsTest.java
@Test
public void testIsDateTime () {
    DateTimeFormatter df = ISODateTimeFormat.dateTime();
    DateTime date = df.parseDateTime("2011-12-11T12:35:45.200+01:00");
    assertEquals(date, AmforeasUtils.isDateTime("2011-12-11T12:35:45.200+01:00"));
    assertNull(AmforeasUtils.isDateTime("2011-12-11 22:00:00"));
    assertNull(AmforeasUtils.isDateTime(""));
    assertNull(AmforeasUtils.isDateTime(null));
    assertNull(AmforeasUtils.isDateTime("2011-01-19"));
    assertNull(AmforeasUtils.isDateTime("20110119"));
    assertNull(AmforeasUtils.isDateTime("22:00:00"));
    assertNull(AmforeasUtils.isDateTime("12:35:45.200+01:00"));
}
 
/**
 * Extract a date from the given string. Assertion fails when invalid date has been provided.
 */
protected Date getDateFromISOString(String isoString) {
    DateTimeFormatter dateFormat = ISODateTimeFormat.dateTime();
    try {
        return dateFormat.parseDateTime(isoString).toDate();
    } catch (IllegalArgumentException iae) {
        fail("Illegal date provided: " + isoString);
        return null;
    }
}
 
/**
 * Create a new {@code DateTimeFormatter} using this factory.
 * <p>If no specific pattern or style has been defined,
 * the supplied {@code fallbackFormatter} will be used.
 * @param fallbackFormatter the fall-back formatter to use when no specific
 * factory properties have been set (can be {@code null}).
 * @return a new date time formatter
 */
public DateTimeFormatter createDateTimeFormatter(DateTimeFormatter fallbackFormatter) {
	DateTimeFormatter dateTimeFormatter = null;
	if (StringUtils.hasLength(this.pattern)) {
		dateTimeFormatter = DateTimeFormat.forPattern(this.pattern);
	}
	else if (this.iso != null && this.iso != ISO.NONE) {
		switch (this.iso) {
			case DATE:
				dateTimeFormatter = ISODateTimeFormat.date();
				break;
			case TIME:
				dateTimeFormatter = ISODateTimeFormat.time();
				break;
			case DATE_TIME:
				dateTimeFormatter = ISODateTimeFormat.dateTime();
				break;
			case NONE:
				/* no-op */
				break;
			default:
				throw new IllegalStateException("Unsupported ISO format: " + this.iso);
		}
	}
	else if (StringUtils.hasLength(this.style)) {
		dateTimeFormatter = DateTimeFormat.forStyle(this.style);
	}

	if (dateTimeFormatter != null && this.timeZone != null) {
		dateTimeFormatter = dateTimeFormatter.withZone(DateTimeZone.forTimeZone(this.timeZone));
	}
	return (dateTimeFormatter != null ? dateTimeFormatter : fallbackFormatter);
}
 
源代码14 项目: Bats   文件: ConvertTimeStampToString.java
public ConvertTimeStampToString(ScalarWriter baseWriter) {
  super(baseWriter);
  final String formatValue = baseWriter.schema().format();
  dateTimeFormatter = formatValue == null
    ? ISODateTimeFormat.dateTime() : DateTimeFormat.forPattern(formatValue);
}
 
源代码15 项目: gsn   文件: Helpers.java
public static String convertTimeFromLongToIso(long timestamp) {
       DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
       DateTime dt = new DateTime(timestamp);
       return fmt.print(dt);
}
 
@Test(expected = NullPointerException.class)
public void testConstructor4WithNullJodaType() {
	new FmtNothing(null, ISODateTimeFormat.dateTime(),
			new IdentityTransform());
}
 
@Deployment
public void testRepeatWithoutEnd() throws Throwable {
  Clock clock = processEngineConfiguration.getClock();
  
  Calendar calendar = Calendar.getInstance();
  Date baseTime = calendar.getTime();

  calendar.add(Calendar.MINUTE, 20);
  //expect to stop boundary jobs after 20 minutes
  DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
  DateTime dt = new DateTime(calendar.getTime());
  String dateStr = fmt.print(dt);

  //reset the timer
  Calendar nextTimeCal = Calendar.getInstance();
  nextTimeCal.setTime(baseTime);
  clock.setCurrentCalendar(nextTimeCal);
  processEngineConfiguration.setClock(clock);

  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("repeatWithEnd");

  runtimeService.setVariable(processInstance.getId(), "EndDateForBoundary", dateStr);

  List<Task> tasks = taskService.createTaskQuery().list();
  assertEquals(1, tasks.size());

  Task task = tasks.get(0);
  assertEquals("Task A", task.getName());

  // Test Boundary Events
  // complete will cause timer to be created
  taskService.complete(task.getId());

  List<Job> jobs = managementService.createTimerJobQuery().list();
  assertEquals(1, jobs.size());

  //boundary events

  waitForJobExecutorToProcessAllJobs(2000, 200);
  // a new job must be prepared because there are 10 repeats 2 seconds interval

  for (int i = 0; i < 9; i++) {
    nextTimeCal.add(Calendar.SECOND, 2);
    clock.setCurrentCalendar(nextTimeCal);
    processEngineConfiguration.setClock(clock);
    waitForJobExecutorToProcessAllJobsAndExecutableTimerJobs(2000, 200);
  }

  nextTimeCal.add(Calendar.SECOND, 2);
  clock.setCurrentCalendar(nextTimeCal);
  processEngineConfiguration.setClock(clock);

  waitForJobExecutorToProcessAllJobs(2000, 200);
  
  // Should not have any other jobs because the endDate is reached
  jobs = managementService.createTimerJobQuery().list();
  assertEquals(0, jobs.size());
  
  tasks = taskService.createTaskQuery().list();
  task = tasks.get(0);
  assertEquals("Task B", task.getName());
  assertEquals(1, tasks.size());
  taskService.complete(task.getId());

  waitForJobExecutorToProcessAllJobs(2000, 200);

  // now All the process instances should be completed
  List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery().list();
  assertEquals(0, processInstances.size());

  // no jobs
  jobs = managementService.createJobQuery().list();
  assertEquals(0, jobs.size());
  jobs = managementService.createTimerJobQuery().list();
  assertEquals(0, jobs.size());

  // no tasks
  tasks = taskService.createTaskQuery().list();
  assertEquals(0, tasks.size());

  processEngineConfiguration.resetClock();
}
 
源代码18 项目: jersey-hmac-auth   文件: TimeUtils.java
public static String getCurrentTimestamp() {
    DateTimeFormatter formatter = ISODateTimeFormat.dateTime();
    return formatter.print(nowInUTC());
}
 
/**
 * Gson invokes this call-back method during serialization when it encounters a field of the
 * specified type. <p>
 *
 * In the implementation of this call-back method, you should consider invoking
 * {@link com.google.gson.JsonSerializationContext#serialize(Object, java.lang.reflect.Type)} method to create JsonElements for any
 * non-trivial field of the {@code src} object. However, you should never invoke it on the
 * {@code src} object itself since that will cause an infinite loop (Gson will call your
 * call-back method again).
 * @param src the object that needs to be converted to Json.
 * @param typeOfSrc the actual type (fully genericized version) of the source object.
 * @return a JsonElement corresponding to the specified object.
 */
@Override
public JsonElement serialize(DateMidnight src, Type typeOfSrc, JsonSerializationContext context)
{
  final DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
  return new JsonPrimitive(fmt.print(src));
}
 
/**
 * Gson invokes this call-back method during deserialization when it encounters a field of the
 * specified type. <p>
 *
 * In the implementation of this call-back method, you should consider invoking
 * {@link com.google.gson.JsonDeserializationContext#deserialize(com.google.gson.JsonElement, java.lang.reflect.Type)} method to create objects
 * for any non-trivial field of the returned object. However, you should never invoke it on the
 * the same type passing {@code json} since that will cause an infinite loop (Gson will call your
 * call-back method again).
 * @param json The Json data being deserialized
 * @param typeOfT The type of the Object to deserialize to
 * @return a deserialized object of the specified type typeOfT which is a subclass of {@code T}
 * @throws com.google.gson.JsonParseException if json is not in the expected format of {@code typeOfT}
 */
@Override
public DateMidnight deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
    throws JsonParseException
{
  // Do not try to deserialize null or empty values
  if (json.getAsString() == null || json.getAsString().isEmpty())
  {
    return null;
  }

  final DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
  return new DateMidnight(fmt.parseDateTime(json.getAsString()));
}