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

The following examples show how to use java.time.LocalDateTime#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: PromService.java    From SkaETL with Apache License 2.0 6 votes vote down vote up
private String buildQuery(String term, String keyLabel, String valueLabel, int range) {
    //build query
    String query = "/api/v1/query_range?";
    try {
        if (StringUtils.isNotBlank(keyLabel) && StringUtils.isNotBlank(valueLabel)) {
            query = query + "query=sum(" + term + "{argFilter})&step=15s";
        } else {
            query = query + "query=" + term + "&step=15s";
        }
        LocalDateTime now = LocalDateTime.ofInstant(Instant.now(), ZoneOffset.UTC);
        query = query + "&end=" + now.toString()+"Z";
        query = query + "&start=" + now.minusMinutes(range).toString()+"Z";
    }catch (Exception e){
        log.error(""+e);
    }
    return query;
}
 
Example 2
Source File: ObjectMapperUtilsTest.java    From jakduk-api with MIT License 5 votes vote down vote up
@Ignore
@Test
public void iso8601Test() throws JsonProcessingException {
    LocalDateTime localDateTime = LocalDateTime.now();

    String expect = "\"" + localDateTime.toString() + "\"";

    System.out.println(expect);
    System.out.println(ObjectMapperUtils.writeValueAsString(localDateTime));

    Assert.assertTrue(expect.equals(ObjectMapperUtils.writeValueAsString(localDateTime)));
}
 
Example 3
Source File: TCKLocalDateTime.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test()
@UseDataProvider("provider_sampleToString")
public void test_toString(int y, int m, int d, int h, int mi, int s, int n, String expected) {
    LocalDateTime t = LocalDateTime.of(y, m, d, h, mi, s, n);
    String str = t.toString();
    assertEquals(str, expected);
}
 
Example 4
Source File: ExcelUtils.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Formats parsed Date as LocalDateTime string at zone UTC to express that we don't know the
 * timezone.
 *
 * @param javaDate Parsed Date representing start of day in UTC
 * @return Formatted {@link LocalDateTime} string of the java.util.Date
 */
private static String formatUTCDateAsLocalDateTime(Date javaDate) {
  // Now back from start of day in UTC to LocalDateTime to express that we don't know the
  // timezone.
  LocalDateTime localDateTime = javaDate.toInstant().atZone(UTC).toLocalDateTime();
  // And format to string
  return localDateTime.toString();
}
 
Example 5
Source File: OneClickImporterServiceImpl.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Formats parsed Date as LocalDateTime string at zone UTC to express that we don't know the
 * timezone.
 *
 * @param javaDate Parsed Date representing start of day in UTC
 * @return Formatted {@link LocalDateTime} string of the java.util.Date
 */
private static String formatUTCDateAsLocalDateTime(Date javaDate) {
  // Now back from start of day in UTC to LocalDateTime to express that we don't know the
  // timezone.
  LocalDateTime localDateTime = javaDate.toInstant().atZone(UTC).toLocalDateTime();
  // And format to string
  return localDateTime.toString();
}
 
Example 6
Source File: TCKLocalDateTime.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 m, int d, int h, int mi, int s, int n, String expected) {
    LocalDateTime t = LocalDateTime.of(y, m, d, h, mi, s, n);
    String str = t.toString();
    assertEquals(str, expected);
}
 
Example 7
Source File: TimestampColumnLocalDateTimeMapper.java    From jadira with Apache License 2.0 4 votes vote down vote up
@Override
public String toNonNullString(LocalDateTime value) {
    return value.toString();
}
 
Example 8
Source File: ActionRequestProcessor.java    From lastaflute with Apache License 2.0 4 votes vote down vote up
protected String askProcessHash(LocalDateTime beginTime) {
    final String bestEffortUnique = beginTime.toString() + Thread.currentThread().getName();
    return Integer.toHexString(bestEffortUnique.hashCode());
}
 
Example 9
Source File: TCKLocalDateTime.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="sampleToString")
public void test_toString(int y, int m, int d, int h, int mi, int s, int n, String expected) {
    LocalDateTime t = LocalDateTime.of(y, m, d, h, mi, s, n);
    String str = t.toString();
    assertEquals(str, expected);
}
 
Example 10
Source File: TCKLocalDateTime.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="sampleToString")
public void test_toString(int y, int m, int d, int h, int mi, int s, int n, String expected) {
    LocalDateTime t = LocalDateTime.of(y, m, d, h, mi, s, n);
    String str = t.toString();
    assertEquals(str, expected);
}
 
Example 11
Source File: TCKLocalDateTime.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="sampleToString")
public void test_toString(int y, int m, int d, int h, int mi, int s, int n, String expected) {
    LocalDateTime t = LocalDateTime.of(y, m, d, h, mi, s, n);
    String str = t.toString();
    assertEquals(str, expected);
}
 
Example 12
Source File: TCKLocalDateTime.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 m, int d, int h, int mi, int s, int n, String expected) {
    LocalDateTime t = LocalDateTime.of(y, m, d, h, mi, s, n);
    String str = t.toString();
    assertEquals(str, expected);
}
 
Example 13
Source File: ImportDateTime.java    From axelor-open-suite with GNU Affero General Public License v3.0 4 votes vote down vote up
public String importDateTime(String inputDateTime) {
  String tm = "[0-9]{2}:[0-9]{2}:[0-9]{2}";
  String patTime =
      "("
          + dt
          + " "
          + tm
          + "|NOW)(\\[("
          + String.format(pat, 4, "y")
          + "?"
          + String.format(pat, 2, "M")
          + "?"
          + String.format(pat, 2, "d")
          + "?"
          + String.format(pat, 2, "H")
          + "?"
          + String.format(pat, 2, "m")
          + "?"
          + String.format(pat, 2, "s")
          + "?"
          + ")\\])?";
  try {
    if (!Strings.isNullOrEmpty(inputDateTime) && inputDateTime.matches(patTime)) {
      List<String> timeList = Arrays.asList(inputDateTime.split("\\["));
      inputDateTime =
          timeList.get(0).equals("NOW") ? LocalDateTime.now().toString() : timeList.get(0);
      if (timeList.size() > 1) {
        LocalDateTime datetime =
            LocalDateTime.parse(inputDateTime, DateTimeFormatter.ISO_DATE_TIME);
        Matcher matcher = Pattern.compile(String.format(pat, 4, "y")).matcher(timeList.get(1));
        if (matcher.find()) datetime = updateYear(datetime, matcher.group());
        matcher = Pattern.compile(String.format(pat, 2, "M")).matcher(timeList.get(1));
        if (matcher.find()) datetime = updateMonth(datetime, matcher.group());
        matcher = Pattern.compile(String.format(pat, 2, "d")).matcher(timeList.get(1));
        if (matcher.find()) datetime = updateDay(datetime, matcher.group());
        matcher = Pattern.compile(String.format(pat, 2, "H")).matcher(timeList.get(1));
        if (matcher.find()) datetime = updateHour(datetime, matcher.group());
        matcher = Pattern.compile(String.format(pat, 2, "m")).matcher(timeList.get(1));
        if (matcher.find()) datetime = updateMinute(datetime, matcher.group());
        matcher = Pattern.compile(String.format(pat, 2, "s")).matcher(timeList.get(1));
        if (matcher.find()) datetime = updateSecond(datetime, matcher.group());
        return datetime.toString();
      }
      return inputDateTime.replace(" ", "T");
    }
    return null;
  } catch (Exception e) {
    return null;
  }
}
 
Example 14
Source File: FailureEntry.java    From syncer with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
FailureEntry(T data, LocalDateTime timestamp, String exception) {
  this.data = data;
  this.timestamp = timestamp.toString();
  this.exception = exception;
}
 
Example 15
Source File: TCKLocalDateTime.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="sampleToString")
public void test_toString(int y, int m, int d, int h, int mi, int s, int n, String expected) {
    LocalDateTime t = LocalDateTime.of(y, m, d, h, mi, s, n);
    String str = t.toString();
    assertEquals(str, expected);
}
 
Example 16
Source File: StringFormatUtils.java    From datakernel with Apache License 2.0 4 votes vote down vote up
public static String formatLocalDateTime(LocalDateTime value) {
	value.format(DATE_TIME_FORMATTER);
	return value.toString();
}
 
Example 17
Source File: TCKLocalDateTime.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 m, int d, int h, int mi, int s, int n, String expected) {
    LocalDateTime t = LocalDateTime.of(y, m, d, h, mi, s, n);
    String str = t.toString();
    assertEquals(str, expected);
}
 
Example 18
Source File: TCKLocalDateTime.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 m, int d, int h, int mi, int s, int n, String expected) {
    LocalDateTime t = LocalDateTime.of(y, m, d, h, mi, s, n);
    String str = t.toString();
    assertEquals(str, expected);
}
 
Example 19
Source File: DateTimePicker.java    From LGoodDatePicker with MIT License 2 votes vote down vote up
/**
 * toStringPermissive, This returns a string representation of the values which are currently
 * stored in the date and time picker. If the last valid value of the date picker is null, then
 * this will return an empty string (""). If the last valid value of the time picker is null,
 * then that portion of the time will be replaced with LocalTime.MIDNIGHT.
 *
 * Javadocs from LocalDateTime.toString():
 *
 * Outputs this date-time as a {@code String}, such as {@code 2007-12-03T10:15:30}.
 * <p>
 * The output will be one of the following ISO-8601 formats:
 * <ul>
 * <li>{@code uuuu-MM-dd'T'HH:mm}</li>
 * <li>{@code uuuu-MM-dd'T'HH:mm:ss}</li>
 * <li>{@code uuuu-MM-dd'T'HH:mm:ss.SSS}</li>
 * <li>{@code uuuu-MM-dd'T'HH:mm:ss.SSSSSS}</li>
 * <li>{@code uuuu-MM-dd'T'HH:mm:ss.SSSSSSSSS}</li>
 * </ul>
 * The format used will be the shortest that outputs the full value of the time where the
 * omitted parts are implied to be zero.
 */
public String toStringPermissive() {
    LocalDateTime dateTime = getDateTimePermissive();
    String text = (dateTime == null) ? "" : dateTime.toString();
    return text;
}
 
Example 20
Source File: DateTimePicker.java    From LGoodDatePicker with MIT License 2 votes vote down vote up
/**
 * toStringStrict, This returns a string representation of the values which are currently stored
 * in the date and time picker. If the last valid value of the date picker or the time picker is
 * null, then this will return an empty string ("").
 *
 * Javadocs from LocalDateTime.toString():
 *
 * Outputs this date-time as a {@code String}, such as {@code 2007-12-03T10:15:30}.
 * <p>
 * The output will be one of the following ISO-8601 formats:
 * <ul>
 * <li>{@code uuuu-MM-dd'T'HH:mm}</li>
 * <li>{@code uuuu-MM-dd'T'HH:mm:ss}</li>
 * <li>{@code uuuu-MM-dd'T'HH:mm:ss.SSS}</li>
 * <li>{@code uuuu-MM-dd'T'HH:mm:ss.SSSSSS}</li>
 * <li>{@code uuuu-MM-dd'T'HH:mm:ss.SSSSSSSSS}</li>
 * </ul>
 * The format used will be the shortest that outputs the full value of the time where the
 * omitted parts are implied to be zero.
 */
public String toStringStrict() {
    LocalDateTime dateTime = getDateTimeStrict();
    String text = (dateTime == null) ? "" : dateTime.toString();
    return text;
}