本文整理了Java中org.joda.time.DateTime.parse()
方法的一些代码示例,展示了DateTime.parse()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DateTime.parse()
方法的具体详情如下:
包路径:org.joda.time.DateTime
类名称:DateTime
方法名:parse
[英]Parses a DateTime from the specified string.
This uses ISODateTimeFormat#dateTimeParser().
[中]从指定的字符串解析日期时间。
这将使用ISODateTimeFormat#dateTimeParser()。
代码示例来源:origin: aws/aws-sdk-java
@JsonCreator
public RestoreEventDataEntity(
@JsonProperty("lifecycleRestorationExpiryTime") String lifecycleRestorationExpiryTime,
@JsonProperty("lifecycleRestoreStorageClass") String lifecycleRestoreStorageClass)
{
if (lifecycleRestorationExpiryTime != null) {
this.lifecycleRestorationExpiryTime = DateTime.parse(lifecycleRestorationExpiryTime);
}
this.lifecycleRestoreStorageClass = lifecycleRestoreStorageClass;
}
代码示例来源:origin: Graylog2/graylog2-server
@Override
public AlertCondition fromPersisted(Map<String, Object> fields, Stream stream) throws ConfigurationException {
final String type = (String)fields.get("type");
return this.alertConditionFactory.createAlertCondition(type,
stream,
(String) fields.get("id"),
DateTime.parse((String) fields.get("created_at")),
(String) fields.get("creator_user_id"),
(Map<String, Object>) fields.get("parameters"),
(String) fields.get("title"));
}
代码示例来源:origin: Graylog2/graylog2-server
/**
* Try to parse a date in ES_DATE_FORMAT format considering it is in UTC and convert it to an ISO8601 date.
* If an error is encountered in the process, it will return the original string.
*/
public static String elasticSearchTimeFormatToISO8601(String time) {
try {
DateTime dt = DateTime.parse(time, ES_DATE_FORMAT_FORMATTER);
return getISO8601String(dt);
} catch (IllegalArgumentException e) {
return time;
}
}
代码示例来源:origin: Graylog2/graylog2-server
private EvaluationContext() {
this(new Message("__dummy", "__dummy", DateTime.parse("2010-07-30T16:03:25Z"))); // first Graylog release
}
代码示例来源:origin: Activiti/Activiti
@Override
public Date resolveDuedate(String duedate, int maxIterations) {
try {
// check if due period was specified
if(duedate.startsWith("P")){
return new DateTime(clockReader.getCurrentTime()).plus(Period.parse(duedate)).toDate();
}
return DateTime.parse(duedate).toDate();
} catch (Exception e) {
throw new ActivitiException("couldn't resolve duedate: " + e.getMessage(), e);
}
}
}
代码示例来源:origin: alibaba/fastjson
DateTime.parse(text) //
: DateTime.parse(text, formatter);
代码示例来源:origin: Codecademy/EventHub
public long findFirstEventIdOnDate(long eventIdForStartDate, int numDaysAfter) {
int startDateOffset = Collections.binarySearch(earliestEventIds, eventIdForStartDate);
if (startDateOffset < 0) {
if (startDateOffset == -1) {
startDateOffset = 0;
} else {
startDateOffset = -startDateOffset - 2;
}
}
String dateOfEvent = dates.get(startDateOffset);
String endDate = DATE_TIME_FORMATTER.print(
DateTime.parse(dateOfEvent, DATE_TIME_FORMATTER).plusDays(numDaysAfter));
int endDateOffset = Collections.binarySearch(dates, endDate);
if (endDateOffset < 0) {
endDateOffset = -endDateOffset - 1;
if (endDateOffset >= earliestEventIds.size()) {
return Long.MAX_VALUE;
}
}
return earliestEventIds.get(endDateOffset);
}
代码示例来源:origin: apache/incubator-pinot
private long sdfToMillis(long value) {
DateTimeFormatter sdfFormatter = DateTimeFormat.forPattern(TIME_COL_FORMAT);
DateTime dateTime = DateTime.parse(Long.toString(value), sdfFormatter);
return dateTime.getMillis();
}
}
代码示例来源:origin: Graylog2/graylog2-server
@GET
@Timed
@ApiOperation(value = "Total count of failed index operations since the given date.")
@ApiResponses(value = {
@ApiResponse(code = 400, message = "Invalid date parameter provided.")
})
@RequiresPermissions(RestPermissions.INDICES_FAILURES)
@Produces(MediaType.APPLICATION_JSON)
@Path("count")
public FailureCount count(@ApiParam(name = "since", value = "ISO8601 date", required = true)
@QueryParam("since") @NotEmpty String since) {
final DateTime sinceDate;
try {
sinceDate = DateTime.parse(since);
} catch (IllegalArgumentException e) {
final String msg = "Invalid date parameter provided: [" + since + "]";
LOG.error(msg, e);
throw new BadRequestException(msg);
}
return FailureCount.create(indexFailureService.countSince(sinceDate));
}
代码示例来源:origin: Graylog2/graylog2-server
@Override
public DateTime deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
switch (jsonParser.currentToken()) {
case VALUE_EMBEDDED_OBJECT:
final Object embeddedObject = jsonParser.getEmbeddedObject();
if (embeddedObject instanceof Date) {
final Date date = (Date) embeddedObject;
return new DateTime(date, DateTimeZone.UTC);
} else {
throw new IllegalStateException("Unsupported token: " + jsonParser.currentToken());
}
case VALUE_STRING:
final String text = jsonParser.getText();
return DateTime.parse(text, FORMATTER).withZone(DateTimeZone.UTC);
default:
throw new IllegalStateException("Unsupported token: " + jsonParser.currentToken());
}
}
}
代码示例来源:origin: Graylog2/graylog2-server
@Override
@Nullable
public Object convert(@Nullable String value) {
if (isNullOrEmpty(value)) {
return null;
}
LOG.debug("Trying to parse date <{}> with pattern <{}>, locale <{}>, and timezone <{}>.", value, dateFormat, locale, timeZone);
final DateTimeFormatter formatter;
if (containsTimeZone) {
formatter = DateTimeFormat
.forPattern(dateFormat)
.withDefaultYear(YearMonth.now(timeZone).getYear())
.withLocale(locale);
} else {
formatter = DateTimeFormat
.forPattern(dateFormat)
.withDefaultYear(YearMonth.now(timeZone).getYear())
.withLocale(locale)
.withZone(timeZone);
}
return DateTime.parse(value, formatter);
}
}
代码示例来源:origin: joda-time/joda-time
/**
* Parses a {@code DateTime} from the specified string.
* <p>
* This uses {@link ISODateTimeFormat#dateTimeParser()}{@code .withOffsetParsed()}
* which is different to passing a {@code String} to the constructor.
* <p>
* Sometimes this method and {@code new DateTime(str)} return different results.
* This can be confusing as the difference is not visible in {@link #toString()}.
* <p>
* When passed a date-time string without an offset, such as '2010-06-30T01:20',
* both the constructor and this method use the default time-zone.
* As such, {@code DateTime.parse("2010-06-30T01:20")} and
* {@code new DateTime("2010-06-30T01:20"))} are equal.
* <p>
* However, when this method is passed a date-time string with an offset,
* the offset is directly parsed and stored.
* As such, {@code DateTime.parse("2010-06-30T01:20+02:00")} and
* {@code new DateTime("2010-06-30T01:20+02:00"))} are NOT equal.
* The object produced via this method has a zone of {@code DateTimeZone.forOffsetHours(2)}.
* The object produced via the constructor has a zone of {@code DateTimeZone.getDefault()}.
*
* @param str the string to parse, not null
* @since 2.0
*/
@FromString
public static DateTime parse(String str) {
return parse(str, ISODateTimeFormat.dateTimeParser().withOffsetParsed());
}
代码示例来源:origin: JodaOrg/joda-time
/**
* Parses a {@code DateTime} from the specified string.
* <p>
* This uses {@link ISODateTimeFormat#dateTimeParser()}{@code .withOffsetParsed()}
* which is different to passing a {@code String} to the constructor.
* <p>
* Sometimes this method and {@code new DateTime(str)} return different results.
* This can be confusing as the difference is not visible in {@link #toString()}.
* <p>
* When passed a date-time string without an offset, such as '2010-06-30T01:20',
* both the constructor and this method use the default time-zone.
* As such, {@code DateTime.parse("2010-06-30T01:20")} and
* {@code new DateTime("2010-06-30T01:20"))} are equal.
* <p>
* However, when this method is passed a date-time string with an offset,
* the offset is directly parsed and stored.
* As such, {@code DateTime.parse("2010-06-30T01:20+02:00")} and
* {@code new DateTime("2010-06-30T01:20+02:00"))} are NOT equal.
* The object produced via this method has a zone of {@code DateTimeZone.forOffsetHours(2)}.
* The object produced via the constructor has a zone of {@code DateTimeZone.getDefault()}.
*
* @param str the string to parse, not null
* @since 2.0
*/
@FromString
public static DateTime parse(String str) {
return parse(str, ISODateTimeFormat.dateTimeParser().withOffsetParsed());
}
代码示例来源:origin: h2oai/h2o-2
@Override public void map( Chunk chks[], NewChunk nchks[] ) {
//done on each node in lieu of rewriting DateTimeFormatter as Iced
DateTimeFormatter dtf = ParseTime.forStrptimePattern(format).withZone(ParseTime.getTimezone());
for( int i=0; i<nchks.length; i++ ) {
NewChunk n =nchks[i];
Chunk c = chks[i];
int rlen = c._len;
for( int r=0; r<rlen; r++ ) {
if (!c.isNA0(r)) {
String date = c._vec.domain((long)c.at0(r));
n.addNum(DateTime.parse(date, dtf).getMillis(), 0);
} else n.addNA();
}
}
}
}.doAll(fr.numCols(),fr).outputFrame(fr._names, null);
代码示例来源:origin: apache/flink
LocalTime.parse("12:12:12"),
123456,
DateTime.parse("2014-03-01T12:12:12.321Z"),
123456L,
ByteBuffer.wrap(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()), // 20.00
代码示例来源:origin: apache/drill
private DateTime parseDateFromPostgres(String date, String pattern) {
String jodaFormat = toJodaFormat(pattern);
DateTimeFormatter format = forPattern(jodaFormat).withLocale(Locale.US);
return parse(date, format).withZoneRetainFields(DateTimeZone.UTC);
}
}
代码示例来源:origin: apache/flink
public static User generateRandomUser(Random rnd) {
return new User(
generateRandomString(rnd, 50),
rnd.nextBoolean() ? null : rnd.nextInt(),
rnd.nextBoolean() ? null : generateRandomString(rnd, 6),
rnd.nextBoolean() ? null : rnd.nextLong(),
rnd.nextDouble(),
null,
rnd.nextBoolean(),
generateRandomStringList(rnd, 20, 30),
generateRandomBooleanList(rnd, 20),
rnd.nextBoolean() ? null : generateRandomStringList(rnd, 20, 20),
generateRandomColor(rnd),
new HashMap<>(),
generateRandomFixed16(rnd),
generateRandomUnion(rnd),
generateRandomAddress(rnd),
generateRandomBytes(rnd),
LocalDate.parse("2014-03-01"),
LocalTime.parse("12:12:12"),
123456,
DateTime.parse("2014-03-01T12:12:12.321Z"),
123456L,
ByteBuffer.wrap(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()),
new Fixed2(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()));
}
代码示例来源:origin: apache/flink
@Override
public User map(Tuple3<String, Integer, String> value) {
User user = new User();
user.setName(value.f0);
user.setFavoriteNumber(value.f1);
user.setFavoriteColor(value.f2);
user.setTypeBoolTest(true);
user.setTypeArrayString(Collections.emptyList());
user.setTypeArrayBoolean(Collections.emptyList());
user.setTypeEnum(Colors.BLUE);
user.setTypeMap(Collections.emptyMap());
user.setTypeBytes(ByteBuffer.allocate(10));
user.setTypeDate(LocalDate.parse("2014-03-01"));
user.setTypeTimeMillis(LocalTime.parse("12:12:12"));
user.setTypeTimeMicros(123456);
user.setTypeTimestampMillis(DateTime.parse("2014-03-01T12:12:12.321Z"));
user.setTypeTimestampMicros(123456L);
// 20.00
user.setTypeDecimalBytes(ByteBuffer.wrap(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()));
// 20.00
user.setTypeDecimalFixed(new Fixed2(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()));
return user;
}
}
代码示例来源:origin: apache/flink
private void output(final AvroOutputFormat<User> outputFormat) throws IOException {
outputFormat.configure(new Configuration());
outputFormat.open(1, 1);
for (int i = 0; i < 100; i++) {
User user = new User();
user.setName("testUser");
user.setFavoriteNumber(1);
user.setFavoriteColor("blue");
user.setTypeBoolTest(true);
user.setTypeArrayString(Collections.emptyList());
user.setTypeArrayBoolean(Collections.emptyList());
user.setTypeEnum(Colors.BLUE);
user.setTypeMap(Collections.emptyMap());
user.setTypeBytes(ByteBuffer.allocate(10));
user.setTypeDate(LocalDate.parse("2014-03-01"));
user.setTypeTimeMillis(LocalTime.parse("12:12:12"));
user.setTypeTimeMicros(123456);
user.setTypeTimestampMillis(DateTime.parse("2014-03-01T12:12:12.321Z"));
user.setTypeTimestampMicros(123456L);
// 20.00
user.setTypeDecimalBytes(ByteBuffer.wrap(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()));
// 20.00
user.setTypeDecimalFixed(new Fixed2(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()));
outputFormat.writeRecord(user);
}
outputFormat.close();
}
代码示例来源:origin: prestodb/presto
"",
new BasicQueryStats(
DateTime.parse("1991-09-06T05:00-05:30"),
DateTime.parse("1991-09-06T05:01-05:30"),
Duration.valueOf("8m"),
Duration.valueOf("7m"),
内容来源于网络,如有侵权,请联系作者删除!