本文整理了Java中java.time.LocalDateTime.toString()
方法的一些代码示例,展示了LocalDateTime.toString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocalDateTime.toString()
方法的具体详情如下:
包路径:java.time.LocalDateTime
类名称:LocalDateTime
方法名:toString
[英]Outputs this date-time as a String, such as 2007-12-03T10:15:30.
The output will be one of the following ISO-8601 formats:
The format used will be the shortest that outputs the full value of the time where the omitted parts are implied to be zero.
[中]以字符串形式输出此日期时间,例如2007-12-03T10:15:30。
输出将是以下ISO-8601格式之一:
*yyyy-MM-dd'HH:MM
*yyyy-MM-dd'HH:MM:ss
*yyyy-MM-dd'HH:MM:ss。SSS
*yyyy-MM-dd'HH:MM:ss。SSSS
*yyyy-MM-dd'HH:MM:ss。SSSSSSSSS
所使用的格式将是最短的,用于输出省略部分暗示为零的时间的完整值。
代码示例来源:origin: alibaba/Sentinel
@Override
public String doAnother() {
return LocalDateTime.now().toString();
}
}
代码示例来源:origin: alibaba/Sentinel
@Override
public String doAnother() {
return LocalDateTime.now().toString();
}
}
代码示例来源:origin: oblac/jodd
@Override
public boolean serialize(final JsonContext jsonContext, final LocalDateTime value) {
jsonContext.writeString(value.toString());
return true;
}
}
代码示例来源:origin: spring-projects/spring-data-redis
@Override
public byte[] convert(LocalDateTime source) {
return fromString(source.toString());
}
}
代码示例来源:origin: SpongePowered/SpongeAPI
@Override
public List<String> complete(CommandSource src, CommandArgs args, CommandContext context) {
String date = LocalDateTime.now().withNano(0).toString();
if (date.startsWith(args.nextIfPresent().orElse(""))) {
return ImmutableList.of(date);
} else {
return ImmutableList.of();
}
}
代码示例来源:origin: google/data-transfer-project
private void copyDateTime(
String key,
CalendarEventModel.CalendarEventTime dateTime,
Map<String, Object> graphCalendar) {
Map<String, String> graphDateTime = new HashMap<>();
graphDateTime.put(
"dateTime",
dateTime.getDateTime().atZoneSameInstant(ZoneId.of("UTC")).toLocalDateTime().toString());
graphDateTime.put("timeZone", "UTC");
graphCalendar.put(key, graphDateTime);
}
代码示例来源:origin: oblac/jodd
@Override
public void set(final PreparedStatement st, final int index, final LocalDateTime value, final int dbSqlType) throws SQLException {
if (value == null) {
st.setNull(index, dbSqlType);
return;
}
if (dbSqlType == Types.TIMESTAMP) {
st.setTimestamp(index, new Timestamp(TimeUtil.toMilliseconds(value)));
return;
}
if (dbSqlType == Types.VARCHAR) {
st.setString(index, value.toString());
return;
}
if (dbSqlType == Types.INTEGER) {
st.setLong(index, TimeUtil.toMilliseconds(value));
}
st.setObject(index, value);
}
代码示例来源:origin: oblac/jodd
@Override
public boolean serialize(final JsonContext jsonContext, final JulianDate value) {
jsonContext.writeString(value.toLocalDateTime().toString());
return true;
}
}
代码示例来源:origin: neo4j/neo4j
@Override
public void writeLocalDateTime( LocalDateTime localDateTime ) throws RuntimeException
{
append( "{localDateTime: " );
append( quote( localDateTime.toString() ) );
append( "}" );
}
代码示例来源:origin: apache/geode
@Test
public void extractWorksCorrectlyForLineFromLogFile() {
String logLine =
"[info 2017/02/07 11:16:36.694 PST locator1 <locator request thread[1]> tid=0x27] Mapped \"{[/v1/async-event-queues],methods=[GET]}\" onto public java.lang.String";
LogLevelExtractor.Result result = LogLevelExtractor.extract(logLine);
assertThat(result).isNotNull();
assertThat(result.getLogLevel()).isEqualTo(Level.INFO);
assertThat(result.getLogTimestamp().toString()).isEqualTo("2017-02-07T11:16:36.694");
}
代码示例来源:origin: apache/geode
@Test
public void extractWorksForFinest() {
String logLine =
"[finest 2017/02/07 11:16:36.694 PST locator1 <locator request thread[1]> tid=0x27] Mapped \"{[/v1/async-event-queues],methods=[GET]}\" onto public java.lang.String";
LogLevelExtractor.Result result = LogLevelExtractor.extract(logLine);
assertThat(result).isNotNull();
assertThat(result.getLogLevel()).isEqualTo(Level.TRACE);
assertThat(result.getLogTimestamp().toString()).isEqualTo("2017-02-07T11:16:36.694");
}
代码示例来源:origin: apache/geode
@Test
public void extractWorksForFine() {
String logLine =
"[fine 2017/02/07 11:16:36.694 PST locator1 <locator request thread[1]> tid=0x27] Mapped \"{[/v1/async-event-queues],methods=[GET]}\" onto public java.lang.String";
LogLevelExtractor.Result result = LogLevelExtractor.extract(logLine);
assertThat(result).isNotNull();
assertThat(result.getLogLevel()).isEqualTo(Level.DEBUG);
assertThat(result.getLogTimestamp().toString()).isEqualTo("2017-02-07T11:16:36.694");
}
代码示例来源:origin: apache/geode
@Test
public void extractWorksForFiner() {
String logLine =
"[finer 2017/02/07 11:16:36.694 PST locator1 <locator request thread[1]> tid=0x27] Mapped \"{[/v1/async-event-queues],methods=[GET]}\" onto public java.lang.String";
LogLevelExtractor.Result result = LogLevelExtractor.extract(logLine);
assertThat(result).isNotNull();
assertThat(result.getLogLevel()).isEqualTo(Level.TRACE);
assertThat(result.getLogTimestamp().toString()).isEqualTo("2017-02-07T11:16:36.694");
}
代码示例来源:origin: linlinjava/litemall
result.put("tokenExpire", userToken.getExpireTime().toString());
result.put("userInfo", userInfo);
return ResponseUtil.ok(result);
代码示例来源:origin: apache/hive
@Override
public ObjectInspector initialize(ObjectInspector[] arguments)
throws UDFArgumentException {
if (arguments.length != 0) {
throw new UDFArgumentLengthException(
"The function CURRENT_TIMESTAMP does not take any arguments, but found "
+ arguments.length);
}
if (currentTimestamp == null) {
SessionState ss = SessionState.get();
ZonedDateTime dateTime = ss.getQueryCurrentTimestamp().atZone(
ss.getConf().getLocalTimeZone());
currentTimestamp = new TimestampWritableV2(
Timestamp.valueOf(dateTime.toLocalDateTime().toString()));
}
return PrimitiveObjectInspectorFactory.writableTimestampObjectInspector;
}
代码示例来源:origin: apache/hive
public static Timestamp stringToTimestamp(String s) {
s = s.trim();
// Handle simpler cases directly avoiding exceptions
if (s.length() == DATE_LENGTH) {
// Its a date!
return Timestamp.ofEpochMilli(Date.valueOf(s).toEpochMilli());
}
try {
return Timestamp.valueOf(s);
} catch (IllegalArgumentException eT) {
// Try zoned timestamp
try {
return Timestamp.valueOf(
TimestampTZUtil.parse(s).getZonedDateTime().toLocalDateTime().toString());
} catch (IllegalArgumentException | DateTimeParseException eTZ) {
// Last attempt
return Timestamp.ofEpochMilli(Date.valueOf(s).toEpochMilli());
}
}
}
}
代码示例来源:origin: apache/hive
public void testTimestampToDate() throws HiveException {
GenericUDFDate udf = new GenericUDFDate();
ObjectInspector valueOI = PrimitiveObjectInspectorFactory.writableTimestampObjectInspector;
ObjectInspector[] arguments = {valueOI};
udf.initialize(arguments);
DeferredObject valueObj = new DeferredJavaObject(new TimestampWritableV2(
Timestamp.valueOf(LocalDateTime.of(109, 06, 30, 4, 17, 52, 0).toString())));
DeferredObject[] args = {valueObj};
DateWritableV2 output = (DateWritableV2) udf.evaluate(args);
assertEquals("to_date() test for TIMESTAMP failed ", "0109-06-30", output.toString());
// Try with null args
DeferredObject[] nullArgs = { new DeferredJavaObject(null) };
output = (DateWritableV2) udf.evaluate(nullArgs);
assertNull("to_date() with null TIMESTAMP", output);
}
代码示例来源:origin: apache/hive
public void testTimestampToDate() throws HiveException {
GenericUDFDateDiff udf = new GenericUDFDateDiff();
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableTimestampObjectInspector;
ObjectInspector valueOI2 = PrimitiveObjectInspectorFactory.writableTimestampObjectInspector;
ObjectInspector[] arguments = {valueOI1, valueOI2};
udf.initialize(arguments);
DeferredObject valueObj1 = new DeferredJavaObject(new TimestampWritableV2(
Timestamp.valueOf(LocalDateTime.of(109, 06, 20, 0, 0, 0, 0).toString())));
DeferredObject valueObj2 = new DeferredJavaObject(new TimestampWritableV2(
Timestamp.valueOf(LocalDateTime.of(109, 06, 17, 0, 0, 0, 0).toString())));
DeferredObject[] args = {valueObj1, valueObj2};
IntWritable output = (IntWritable) udf.evaluate(args);
assertEquals("datediff() test for TIMESTAMP failed ", "3", output.toString());
// Test with null args
args = new DeferredObject[] { new DeferredJavaObject(null), valueObj2 };
assertNull("date_add() 1st arg null", udf.evaluate(args));
args = new DeferredObject[] { valueObj1, new DeferredJavaObject(null) };
assertNull("date_add() 2nd arg null", udf.evaluate(args));
args = new DeferredObject[] { new DeferredJavaObject(null), new DeferredJavaObject(null) };
assertNull("date_add() both args null", udf.evaluate(args));
}
代码示例来源:origin: apache/hive
public void testTimestampToDate() throws HiveException {
GenericUDFDateAdd udf = new GenericUDFDateAdd();
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableTimestampObjectInspector;
ObjectInspector valueOI2 = PrimitiveObjectInspectorFactory.javaIntObjectInspector;
ObjectInspector[] arguments = {valueOI1, valueOI2};
udf.initialize(arguments);
DeferredObject valueObj1 = new DeferredJavaObject(new TimestampWritableV2(
Timestamp.valueOf(LocalDateTime.of(109, 06, 20, 4, 17, 52, 0).toString())));
DeferredObject valueObj2 = new DeferredJavaObject(new Integer("3"));
DeferredObject[] args = {valueObj1, valueObj2};
DateWritableV2 output = (DateWritableV2) udf.evaluate(args);
assertEquals("date_add() test for TIMESTAMP failed ", "0109-06-23", output.toString());
// Test with null args
args = new DeferredObject[] { new DeferredJavaObject(null), valueObj2 };
assertNull("date_add() 1st arg null", udf.evaluate(args));
args = new DeferredObject[] { valueObj1, new DeferredJavaObject(null) };
assertNull("date_add() 2nd arg null", udf.evaluate(args));
args = new DeferredObject[] { new DeferredJavaObject(null), new DeferredJavaObject(null) };
assertNull("date_add() both args null", udf.evaluate(args));
}
代码示例来源:origin: apache/hive
public void testTimestampToDate() throws HiveException {
GenericUDFDateSub udf = new GenericUDFDateSub();
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableTimestampObjectInspector;
ObjectInspector valueOI2 = PrimitiveObjectInspectorFactory.javaIntObjectInspector;
ObjectInspector[] arguments = {valueOI1, valueOI2};
udf.initialize(arguments);
DeferredObject valueObj1 = new DeferredJavaObject(new TimestampWritableV2(
Timestamp.valueOf(LocalDateTime.of(109, 06, 20, 4, 17, 52, 0).toString())));
DeferredObject valueObj2 = new DeferredJavaObject(new Integer("3"));
DeferredObject[] args = {valueObj1, valueObj2};
DateWritableV2 output = (DateWritableV2) udf.evaluate(args);
assertEquals("date_sub() test for TIMESTAMP failed ", "0109-06-17", output.toString());
// Test with null args
args = new DeferredObject[] { new DeferredJavaObject(null), valueObj2 };
assertNull("date_add() 1st arg null", udf.evaluate(args));
args = new DeferredObject[] { valueObj1, new DeferredJavaObject(null) };
assertNull("date_add() 2nd arg null", udf.evaluate(args));
args = new DeferredObject[] { new DeferredJavaObject(null), new DeferredJavaObject(null) };
assertNull("date_add() both args null", udf.evaluate(args));
}
内容来源于网络,如有侵权,请联系作者删除!