Java Code Examples for java.time.ZonedDateTime#toString()

The following examples show how to use java.time.ZonedDateTime#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AuditRecordControllerTests.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
@Test
public void testRetrieveAuditRecordsFromGivenDateToNull() throws Exception {
	ZonedDateTime betweenTime = endDate.withZoneSameInstant(ZoneOffset.UTC);
	String fromDate = betweenTime.toString();

	mockMvc.perform(get("/audit-records?fromDate=" + fromDate).accept(MediaType.APPLICATION_JSON))
			.andDo(print())
			.andExpect(status().isOk())
			.andExpect(jsonPath("$.content.*", hasSize(2)))

			.andExpect(jsonPath("$.content[0].auditRecordId", is(12)))
			.andExpect(jsonPath("$.content[0].correlationId", is("myStream")))
			.andExpect(jsonPath("$.content[0].auditAction", is("UNDEPLOY")))

			.andExpect(jsonPath("$.content[1].auditRecordId", is(13)))
			.andExpect(jsonPath("$.content[1].correlationId", is("myStream")))
			.andExpect(jsonPath("$.content[1].auditAction", is("DELETE")));
}
 
Example 2
Source File: AuditRecordControllerTests.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
@Test
public void testRetrieveAuditRecordsFromNullToGivenDate() throws Exception {
	ZonedDateTime time = betweenDate.withZoneSameInstant(ZoneOffset.UTC);
	String toDate = time.toString();

	mockMvc.perform(get("/audit-records?toDate=" + toDate).accept(MediaType.APPLICATION_JSON))
			.andDo(print())
			.andExpect(status().isOk())
			.andExpect(jsonPath("$.content.*", hasSize(6)))

			.andExpect(jsonPath("$.content[4].auditRecordId", is(9)))
			.andExpect(jsonPath("$.content[4].correlationId", is("myStream")))
			.andExpect(jsonPath("$.content[4].auditAction", is("CREATE")))

			.andExpect(jsonPath("$.content[5].auditRecordId", is(10)))
			.andExpect(jsonPath("$.content[5].correlationId", is("myStream1")))
			.andExpect(jsonPath("$.content[5].auditAction", is("CREATE")));
}
 
Example 3
Source File: AuditRecordControllerTests.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
@Test
public void testRetrieveAuditRecordsBetweenTwoGivenDates() throws Exception {
	ZonedDateTime betweenTime = betweenDate.withZoneSameInstant(ZoneOffset.UTC);
	String fromDate = betweenTime.toString();

	ZonedDateTime endTime = endDate.withZoneSameInstant(ZoneOffset.UTC);
	String toDate = endTime.toString();

	mockMvc.perform(get("/audit-records?fromDate=" + fromDate + "&toDate=" + toDate)
			.accept(MediaType.APPLICATION_JSON))
			.andDo(print())
			.andExpect(status().isOk())
			.andExpect(jsonPath("$.content.*", hasSize(1)))

			.andExpect(jsonPath("$.content[0].auditRecordId", is(11)))
			.andExpect(jsonPath("$.content[0].correlationId", is("myStream2")))
			.andExpect(jsonPath("$.content[0].auditAction", is("CREATE")));
}
 
Example 4
Source File: DocumentChangeLogService.java    From metasfresh-webui-api-legacy with GNU General Public License v3.0 6 votes vote down vote up
private String formatTimestamp(final ZonedDateTime timestamp, final String adLanguage)
{
	if (timestamp == null)
	{
		return null;
	}

	try
	{
		final Language language = Language.getLanguage(adLanguage);
		final SimpleDateFormat dateFormat = DisplayType.getDateFormat(DisplayType.DateTime, language);
		return dateFormat.format(TimeUtil.asDate(timestamp));
	}
	catch (Exception ex)
	{
		logger.warn("Failed formating {}. Returning it a string.", timestamp, ex);
		return timestamp.toString();
	}
}
 
Example 5
Source File: PDTFromStringTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testDefaultToStringAndBack ()
{
  final ZonedDateTime aDT = PDTFactory.getCurrentZonedDateTime ();
  String sDT = aDT.toString ();
  assertEquals (aDT, ZonedDateTime.parse (sDT));

  final LocalDateTime aLDT = PDTFactory.getCurrentLocalDateTime ();
  sDT = aLDT.toString ();
  assertEquals (aLDT, LocalDateTime.parse (sDT));

  final LocalDate aLD = PDTFactory.getCurrentLocalDate ();
  sDT = aLD.toString ();
  assertEquals (aLD, LocalDate.parse (sDT));

  final LocalTime aLT = PDTFactory.getCurrentLocalTime ();
  sDT = aLT.toString ();
  assertEquals (aLT, LocalTime.parse (sDT));
}
 
Example 6
Source File: CurrencyRatesHandler.java    From prebid-server-java with Apache License 2.0 5 votes vote down vote up
@Override
public void handle(RoutingContext context) {
    final ZonedDateTime lastUpdated = currencyConversionService.getLastUpdated();
    final String lastUpdatedString = lastUpdated != null ? lastUpdated.toString() : "no value";
    try {
        context.response().end(mapper.mapper().writeValueAsString(Response.of(lastUpdatedString)));
    } catch (IOException e) {
        logger.error("Critical error when marshaling latest currency rates update response", e);
        context.response().setStatusCode(HttpResponseStatus.INTERNAL_SERVER_ERROR.code()).end();
    }
}
 
Example 7
Source File: ZonedDateTimeAdapter.java    From timbuctoo with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String marshal(ZonedDateTime value) throws Exception {
  if (value == null) {
    return null;
  }
  return value.toString();
}
 
Example 8
Source File: ZonedDateTimeWriteConverter.java    From bearchoke with Apache License 2.0 5 votes vote down vote up
@Override
public String convert(ZonedDateTime zdt) {
    String result = null;

        if (log.isTraceEnabled()) {
            log.trace("Converting ZonedDateTime {} to string", zdt.toString());
        }

        result = zdt.toString();

    return result;
}
 
Example 9
Source File: ZonedDateTimeAdapter.java    From Java-OCA-OCPP with MIT License 4 votes vote down vote up
@Override
public String marshal(ZonedDateTime zonedDateTime) throws Exception {
  return zonedDateTime.toString();
}
 
Example 10
Source File: TimestampColumnZonedDateTimeMapper.java    From jadira with Apache License 2.0 4 votes vote down vote up
@Override
public String toNonNullString(ZonedDateTime value) {
    return value.toString();
}
 
Example 11
Source File: JsonMapperTCK.java    From vertx-codegen with Apache License 2.0 4 votes vote down vote up
@GenIgnore
static String serializeZonedDateTime(ZonedDateTime value) {
  return value.toString();
}
 
Example 12
Source File: TCKZonedDateTime.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="sampleToString")
public void test_toString(int y, int o, int d, int h, int m, int s, int n, String zoneId, String expected) {
    ZonedDateTime t = ZonedDateTime.of(dateTime(y, o, d, h, m, s, n), ZoneId.of(zoneId));
    String str = t.toString();
    assertEquals(str, expected);
}
 
Example 13
Source File: Mappers.java    From vertx-service-proxy with Apache License 2.0 4 votes vote down vote up
public static String serializeZonedDateTime(ZonedDateTime value) throws IllegalArgumentException {
  return (value != null) ? value.toString() : null;
}
 
Example 14
Source File: TCKZonedDateTime.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="sampleToString")
public void test_toString(int y, int o, int d, int h, int m, int s, int n, String zoneId, String expected) {
    ZonedDateTime t = ZonedDateTime.of(dateTime(y, o, d, h, m, s, n), ZoneId.of(zoneId));
    String str = t.toString();
    assertEquals(str, expected);
}
 
Example 15
Source File: TCKZonedDateTime.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="sampleToString")
public void test_toString(int y, int o, int d, int h, int m, int s, int n, String zoneId, String expected) {
    ZonedDateTime t = ZonedDateTime.of(dateTime(y, o, d, h, m, s, n), ZoneId.of(zoneId));
    String str = t.toString();
    assertEquals(str, expected);
}
 
Example 16
Source File: TCKZonedDateTime.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="sampleToString")
public void test_toString(int y, int o, int d, int h, int m, int s, int n, String zoneId, String expected) {
    ZonedDateTime t = ZonedDateTime.of(dateTime(y, o, d, h, m, s, n), ZoneId.of(zoneId));
    String str = t.toString();
    assertEquals(str, expected);
}
 
Example 17
Source File: TCKZonedDateTime.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="sampleToString")
public void test_toString(int y, int o, int d, int h, int m, int s, int n, String zoneId, String expected) {
    ZonedDateTime t = ZonedDateTime.of(dateTime(y, o, d, h, m, s, n), ZoneId.of(zoneId));
    String str = t.toString();
    assertEquals(str, expected);
}
 
Example 18
Source File: TCKZonedDateTime.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="sampleToString")
public void test_toString(int y, int o, int d, int h, int m, int s, int n, String zoneId, String expected) {
    ZonedDateTime t = ZonedDateTime.of(dateTime(y, o, d, h, m, s, n), ZoneId.of(zoneId));
    String str = t.toString();
    assertEquals(str, expected);
}
 
Example 19
Source File: TCKZonedDateTime.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="sampleToString")
public void test_toString(int y, int o, int d, int h, int m, int s, int n, String zoneId, String expected) {
    ZonedDateTime t = ZonedDateTime.of(dateTime(y, o, d, h, m, s, n), ZoneId.of(zoneId));
    String str = t.toString();
    assertEquals(str, expected);
}
 
Example 20
Source File: Utils.java    From td-ameritrade-client with Apache License 2.0 2 votes vote down vote up
/**
 *
 * @param epoch number of milliseconds since epoch
 * @return formatted string e.g. January 25, 2019 at 3:55:06 AM CST
 */
public static String epochToStr(Long epoch){
  ZonedDateTime dateTime = Instant.ofEpochMilli(epoch).atZone(ZoneId.systemDefault());
  return dateTime.toString();
}