当前位置: 首页>>代码示例>>Java>>正文


Java ISO类代码示例

本文整理汇总了Java中org.springframework.format.annotation.DateTimeFormat.ISO的典型用法代码示例。如果您正苦于以下问题:Java ISO类的具体用法?Java ISO怎么用?Java ISO使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ISO类属于org.springframework.format.annotation.DateTimeFormat包,在下文中一共展示了ISO类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: events

import org.springframework.format.annotation.DateTimeFormat.ISO; //导入依赖的package包/类
@GetMapping("events")
HttpEntity<Resources<?>> events(PagedResourcesAssembler<AbstractEvent<?>> assembler,
		@SortDefault("publicationDate") Pageable pageable,
		@RequestParam(required = false) @DateTimeFormat(iso = ISO.DATE_TIME) LocalDateTime since,
		@RequestParam(required = false) String type) {

	QAbstractEvent $ = QAbstractEvent.abstractEvent;

	BooleanBuilder builder = new BooleanBuilder();

	// Apply date
	Optional.ofNullable(since).ifPresent(it -> builder.and($.publicationDate.after(it)));

	// Apply type
	Optional.ofNullable(type) //
			.flatMap(events::findEventTypeByName) //
			.ifPresent(it -> builder.and($.instanceOf(it)));

	Page<AbstractEvent<?>> result = events.findAll(builder, pageable);

	PagedResources<Resource<AbstractEvent<?>>> resource = assembler.toResource(result, event -> toResource(event));
	resource
			.add(links.linkTo(methodOn(EventController.class).events(assembler, pageable, since, type)).withRel("events"));

	return ResponseEntity.ok(resource);
}
 
开发者ID:olivergierke,项目名称:sos,代码行数:27,代码来源:EventController.java

示例2: createDateTimeFormatter

import org.springframework.format.annotation.DateTimeFormat.ISO; //导入依赖的package包/类
/**
 * 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 = DateTimeFormatter.ofPattern(this.pattern);
	}
	else if (this.iso != null && this.iso != ISO.NONE) {
		switch (this.iso) {
			case DATE:
				dateTimeFormatter = DateTimeFormatter.ISO_DATE;
				break;
			case TIME:
				dateTimeFormatter = DateTimeFormatter.ISO_TIME;
				break;
			case DATE_TIME:
				dateTimeFormatter = DateTimeFormatter.ISO_DATE_TIME;
				break;
			case NONE:
				/* no-op */
				break;
			default:
				throw new IllegalStateException("Unsupported ISO format: " + this.iso);
		}
	}
	else if (this.dateStyle != null && this.timeStyle != null) {
		dateTimeFormatter = DateTimeFormatter.ofLocalizedDateTime(this.dateStyle, this.timeStyle);
	}
	else if (this.dateStyle != null) {
		dateTimeFormatter = DateTimeFormatter.ofLocalizedDate(this.dateStyle);
	}
	else if (this.timeStyle != null) {
		dateTimeFormatter = DateTimeFormatter.ofLocalizedTime(this.timeStyle);
	}

	if (dateTimeFormatter != null && this.timeZone != null) {
		dateTimeFormatter = dateTimeFormatter.withZone(this.timeZone.toZoneId());
	}
	return (dateTimeFormatter != null ? dateTimeFormatter : fallbackFormatter);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:47,代码来源:DateTimeFormatterFactory.java

示例3: shouldUseCorrectOrder

import org.springframework.format.annotation.DateTimeFormat.ISO; //导入依赖的package包/类
@Test
public void shouldUseCorrectOrder() throws Exception {
	DateFormatter formatter = new DateFormatter();
	formatter.setTimeZone(UTC);
	formatter.setStyle(DateFormat.SHORT);
	formatter.setStylePattern("L-");
	formatter.setIso(ISO.DATE_TIME);
	formatter.setPattern("yyyy");
	Date date = getDate(2009, Calendar.JUNE, 1, 14, 23, 5, 3);

	assertThat("uses pattern",formatter.print(date, Locale.US), is("2009"));

	formatter.setPattern("");
	assertThat("uses ISO", formatter.print(date, Locale.US), is("2009-06-01T14:23:05.003+0000"));

	formatter.setIso(ISO.NONE);
	assertThat("uses style pattern", formatter.print(date, Locale.US), is("June 1, 2009"));

	formatter.setStylePattern("");
	assertThat("uses style", formatter.print(date, Locale.US), is("6/1/09"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:DateFormatterTests.java

示例4: getSearchTemporal

import org.springframework.format.annotation.DateTimeFormat.ISO; //导入依赖的package包/类
@RequestMapping(value = REQUEST_PATH_TEMPORAL, method = RequestMethod.GET)
public ResponseEntity<?> getSearchTemporal(@RequestParam(value = URLConstants.PARAM_LEVELS, required = true) List<String> levels, @RequestParam(value = URLConstants.PARAM_TYPES, required = true) List<String> types, @RequestParam(value = URLConstants.PARAM_SINCE, required = true) @DateTimeFormat(iso = ISO.DATE_TIME) Date since, @RequestParam(value = URLConstants.PARAM_PAGE, required = false) Integer page, @RequestParam(value = URLConstants.PARAM_IRIS, required = false, defaultValue = "false") boolean iris, @RequestParam(value = URLConstants.PARAM_DESC, required = false, defaultValue = "false") boolean descriptions, HttpServletRequest request) {
    if (page == null) {

        AnnotationCollectionSearch<C> annotationCollectionSearch = (ClientPreference clientPref) -> annotationCollectionSearchService.searchAnnotationCollectionByTemporal(levels, types, since, clientPref);

        return processCollectionSearchRequest(annotationCollectionSearch, request);
    } else {
        AnnotationPageSearch<P> annotationPageSearch = (boolean embeddedDescriptions) -> {

            ServiceResponse<List<A>> serviceResponse = annotationSearchService.searchAnnotationsByTemporal(levels, types, since);
            Status status = serviceResponse.getStatus();

            if (!status.equals(Status.OK)) {
                return new ServiceResponse<P>(status, null);
            }

            List<A> annotations = serviceResponse.getObj();

            return annotationPageSearchService.buildAnnotationPageByTemporal(annotations, levels, types, since, page, embeddedDescriptions);
        };

        return processPageSearchRequest(annotationPageSearch, iris, descriptions);
    }
}
 
开发者ID:dlcs,项目名称:elucidate-server,代码行数:26,代码来源:AbstractAnnotationSearchController.java

示例5: yahooFinanceHistoric

import org.springframework.format.annotation.DateTimeFormat.ISO; //导入依赖的package包/类
/** 
 * @param tickersString a ticker with extension, e.g. ABC.L
 * @return a CSV string with header row of Date,Open,High,Low,Close,Volume,Adj Close
 */
@RequestMapping("/yahoo/historic/{ticker:.+}/{date}")
public ResponseEntity<String> yahooFinanceHistoric(
    @PathVariable @NotNull String ticker,
    @PathVariable @DateTimeFormat(iso = ISO.DATE) LocalDate date) {
  logger.info("yahooFinanceHistoricDirect({})", ticker);
  CharSeq results = doTicksYahooFinanceHistoric(
      kennel.parseTickersString.apply(ticker).head(), date);

  // create the return type required by this mock API...
  HttpHeaders headers = new HttpHeaders();
  headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
  headers.setContentDispositionFormData("file", "quotes.csv");
  ResponseEntity<String> response = new ResponseEntity<>(results.toString(), headers, HttpStatus.OK);
  return response;
}
 
开发者ID:the-james-burton,项目名称:the-turbine,代码行数:20,代码来源:FinanceController.java

示例6: createDateTimeFormatter

import org.springframework.format.annotation.DateTimeFormat.ISO; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:41,代码来源:DateTimeFormatterFactory.java

示例7: createDateTimeFormatterInOrderOfPropertyPriority

import org.springframework.format.annotation.DateTimeFormat.ISO; //导入依赖的package包/类
@Test
public void createDateTimeFormatterInOrderOfPropertyPriority() throws Exception {
	factory.setStyle("SS");
	String value = applyLocale(factory.createDateTimeFormatter()).print(dateTime);
	assertTrue(value.startsWith("10/21/09"));
	assertTrue(value.endsWith("12:10 PM"));

	factory.setIso(ISO.DATE);
	assertThat(applyLocale(factory.createDateTimeFormatter()).print(dateTime), is("2009-10-21"));

	factory.setPattern("yyyyMMddHHmmss");
	assertThat(factory.createDateTimeFormatter().print(dateTime), is("20091021121000"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:14,代码来源:DateTimeFormatterFactoryTests.java

示例8: stringToDateWithGlobalFormat

import org.springframework.format.annotation.DateTimeFormat.ISO; //导入依赖的package包/类
@Test
public void stringToDateWithGlobalFormat() throws Exception {
	// SPR-10105
	JodaTimeFormatterRegistrar registrar = new JodaTimeFormatterRegistrar();
	DateTimeFormatterFactory factory = new DateTimeFormatterFactory();
	factory.setIso(ISO.DATE_TIME);
	registrar.setDateTimeFormatter(factory.createDateTimeFormatter());
	setUp(registrar);
	// This is a format that cannot be parsed by new Date(String)
	String string = "2009-10-31T07:00:00.000-05:00";
	Date date = this.conversionService.convert(string, Date.class);
	assertNotNull(date);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:14,代码来源:JodaTimeFormattingTests.java

示例9: createDateTimeFormatterInOrderOfPropertyPriority

import org.springframework.format.annotation.DateTimeFormat.ISO; //导入依赖的package包/类
@Test
public void createDateTimeFormatterInOrderOfPropertyPriority() throws Exception {
	factory.setStylePattern("SS");
	String value = applyLocale(factory.createDateTimeFormatter()).format(dateTime);
	assertTrue(value.startsWith("10/21/09"));
	assertTrue(value.endsWith("12:10 PM"));

	factory.setIso(ISO.DATE);
	assertThat(applyLocale(factory.createDateTimeFormatter()).format(dateTime), is("2009-10-21"));

	factory.setPattern("yyyyMMddHHmmss");
	assertThat(factory.createDateTimeFormatter().format(dateTime), is("20091021121000"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:14,代码来源:DateTimeFormatterFactoryTests.java

示例10: shouldPrintAndParseISODate

import org.springframework.format.annotation.DateTimeFormat.ISO; //导入依赖的package包/类
@Test
public void shouldPrintAndParseISODate() throws Exception {
	DateFormatter formatter = new DateFormatter();
	formatter.setTimeZone(UTC);
	formatter.setIso(ISO.DATE);
	Date date = getDate(2009, Calendar.JUNE, 1, 14, 23, 5, 3);
	assertThat(formatter.print(date, Locale.US), is("2009-06-01"));
	assertThat(formatter.parse("2009-6-01", Locale.US),
			is(getDate(2009, Calendar.JUNE, 1)));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:11,代码来源:DateFormatterTests.java

示例11: shouldPrintAndParseISOTime

import org.springframework.format.annotation.DateTimeFormat.ISO; //导入依赖的package包/类
@Test
public void shouldPrintAndParseISOTime() throws Exception {
	DateFormatter formatter = new DateFormatter();
	formatter.setTimeZone(UTC);
	formatter.setIso(ISO.TIME);
	Date date = getDate(2009, Calendar.JANUARY, 1, 14, 23, 5, 3);
	assertThat(formatter.print(date, Locale.US), is("14:23:05.003+0000"));
	assertThat(formatter.parse("14:23:05.003+0000", Locale.US),
			is(getDate(1970, Calendar.JANUARY, 1, 14, 23, 5, 3)));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:11,代码来源:DateFormatterTests.java

示例12: shouldParseIsoTimeWithZeros

import org.springframework.format.annotation.DateTimeFormat.ISO; //导入依赖的package包/类
@Test
public void shouldParseIsoTimeWithZeros() throws Exception {
	DateFormatter formatter = new DateFormatter();
	formatter.setIso(ISO.TIME);
	Date date = formatter.parse("12:00:00.000-00005", Locale.US);
	System.out.println(date);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:8,代码来源:DateFormatterTests.java

示例13: shouldPrintAndParseISODateTime

import org.springframework.format.annotation.DateTimeFormat.ISO; //导入依赖的package包/类
@Test
public void shouldPrintAndParseISODateTime() throws Exception {
	DateFormatter formatter = new DateFormatter();
	formatter.setTimeZone(UTC);
	formatter.setIso(ISO.DATE_TIME);
	Date date = getDate(2009, Calendar.JUNE, 1, 14, 23, 5, 3);
	assertThat(formatter.print(date, Locale.US), is("2009-06-01T14:23:05.003+0000"));
	assertThat(formatter.parse("2009-06-01T14:23:05.003+0000", Locale.US), is(date));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:10,代码来源:DateFormatterTests.java

示例14: stringToDateWithGlobalFormat

import org.springframework.format.annotation.DateTimeFormat.ISO; //导入依赖的package包/类
@Test
public void stringToDateWithGlobalFormat() throws Exception {
	// SPR-10105
	DateFormatterRegistrar registrar = new DateFormatterRegistrar();
	DateFormatter dateFormatter = new DateFormatter();
	dateFormatter.setIso(ISO.DATE_TIME);
	registrar.setFormatter(dateFormatter);
	setUp(registrar);
	// This is a format that cannot be parsed by new Date(String)
	String string = "2009-06-01T14:23:05.003+0000";
	Date date = this.conversionService.convert(string, Date.class);
	assertNotNull(date);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:14,代码来源:DateFormattingTests.java

示例15: getAvailability

import org.springframework.format.annotation.DateTimeFormat.ISO; //导入依赖的package包/类
@ResponseBody
@RequestMapping(value="/user/{emailAddress}/availability",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
public Availability getAvailability(@PathVariable String emailAddress, @RequestParam(value="start") @DateTimeFormat(iso=ISO.DATE_TIME) Date start, @RequestParam(value="end") @DateTimeFormat(iso=ISO.DATE_TIME) Date end, @RequestParam Integer timezoneOffset){
	Assert.isTrue(!start.after(end), "start cannot be after end");
	start = DateUtils.addMinutes(start, timezoneOffset);
	end = DateUtils.addMinutes(end, timezoneOffset);
	return availabilityService.getAvailability(emailAddress, start, end).orElseThrow(NotFoundException::new);
}
 
开发者ID:candrews,项目名称:availability,代码行数:9,代码来源:AvailabilityController.java


注:本文中的org.springframework.format.annotation.DateTimeFormat.ISO类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。