org.joda.time.format.DateTimeFormatter.withOffsetParsed()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(220)

本文整理了Java中org.joda.time.format.DateTimeFormatter.withOffsetParsed()方法的一些代码示例,展示了DateTimeFormatter.withOffsetParsed()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DateTimeFormatter.withOffsetParsed()方法的具体详情如下:
包路径:org.joda.time.format.DateTimeFormatter
类名称:DateTimeFormatter
方法名:withOffsetParsed

DateTimeFormatter.withOffsetParsed介绍

[英]Returns a new formatter that will create a datetime with a time zone equal to that of the offset of the parsed string.

After calling this method, a string '2004-06-09T10:20:30-08:00' will create a datetime with a zone of -08:00 (a fixed zone, with no daylight savings rules). If the parsed string represents a local time (no zone offset) the parsed datetime will be in the default zone.

Calling this method sets the override zone to null. Calling the override zone method sets this flag off.
[中]返回一个新的格式化程序,该格式化程序将创建一个时区等于已解析字符串偏移量时区的datetime。
调用此方法后,字符串“2004-06-09T10:20:30-08:00”将创建区域为-08:00的日期时间(固定区域,无夏令时规则)。如果解析的字符串表示本地时间(无区域偏移),则解析的日期时间将位于默认区域。
调用此方法将覆盖区域设置为null。调用override zone方法将关闭此标志。

代码示例

代码示例来源:origin: stackoverflow.com

final DateTimeFormatter df = DateTimeFormat
    .forPattern("EEE MMM dd HH:mm:ss 'GMT'Z yyyy");
final DateTime dateTime = df.withOffsetParsed()
    .parseDateTime("Mon Aug 24 12:36:46 GMT+1000 2009");

代码示例来源:origin: Graylog2/graylog2-server

private DateTime parseDateTime(String s) {
    if (Strings.isNullOrEmpty(s)) {
      throw new IllegalArgumentException("Null or empty string");
    }
    final DateTimeFormatter formatter;
    if (s.contains("T")) {
      formatter = ISODateTimeFormat.dateTime();
    } else {
      formatter = Tools.timeFormatterWithOptionalMilliseconds();
    }
    // Use withOffsetParsed() to keep the timezone!
    return formatter.withOffsetParsed().parseDateTime(s);
  }
}

代码示例来源:origin: stackoverflow.com

public static void testDate() 
{
 DateTimeFormatter df = DateTimeFormat.forPattern("dd MM yyyy HH:mm:ss.SSS Z");
 DateTime temp = df.withOffsetParsed().parseDateTime("30 11 2012 12:08:56.235 +0700");
 DateTimeZone theZone = temp.getZone();
 Date date = temp.toDate();
 DateTime dateTime = new DateTime(date);
 DateTimeFormatter df2 = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSZZ");
 DateTimeFormatter df3 = df2.withZone(theZone);
 System.out.println(dateTime.toString(df2));
 System.out.println(dateTime.toString(df3));
}

代码示例来源:origin: prestodb/presto

/**
 * Parse a string (optionally containing a zone) as a value of TIMESTAMP WITH TIME ZONE type.
 * If the string doesn't specify a zone, it is interpreted in {@code timeZoneKey} zone.
 * <p>
 * For example: {@code "2000-01-01 01:23:00"} is parsed to TIMESTAMP WITH TIME ZONE
 * {@code 2000-01-01T01:23:00 <provided zone>} and {@code "2000-01-01 01:23:00 +01:23"}
 * is parsed to TIMESTAMP WITH TIME ZONE {@code 2000-01-01T01:23:00.000+01:23}.
 *
 * @return stack representation of TIMESTAMP WITH TIME ZONE type
 */
public static long parseTimestampWithTimeZone(TimeZoneKey timeZoneKey, String timestampWithTimeZone)
{
  DateTime dateTime = TIMESTAMP_WITH_OR_WITHOUT_TIME_ZONE_FORMATTER.withChronology(getChronology(timeZoneKey)).withOffsetParsed().parseDateTime(timestampWithTimeZone);
  return packDateTimeWithZone(dateTime);
}

代码示例来源: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: joda-time/joda-time

/**
 * Parses a {@code MutableDateTime} from the specified string.
 * <p>
 * This uses {@link ISODateTimeFormat#dateTimeParser()}.
 * 
 * @param str  the string to parse, not null
 * @since 2.0
 */
@FromString
public static MutableDateTime parse(String str) {
  return parse(str, ISODateTimeFormat.dateTimeParser().withOffsetParsed());
}

代码示例来源:origin: joda-time/joda-time

/**
 * Parses a {@code DateMidnight} from the specified string.
 * <p>
 * This uses {@link ISODateTimeFormat#dateTimeParser()}.
 * 
 * @param str  the string to parse, not null
 * @since 2.0
 */
@FromString
public static DateMidnight 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: JodaOrg/joda-time

/**
 * Parses a {@code MutableDateTime} from the specified string.
 * <p>
 * This uses {@link ISODateTimeFormat#dateTimeParser()}.
 * 
 * @param str  the string to parse, not null
 * @since 2.0
 */
@FromString
public static MutableDateTime parse(String str) {
  return parse(str, ISODateTimeFormat.dateTimeParser().withOffsetParsed());
}

代码示例来源:origin: JodaOrg/joda-time

/**
 * Parses a {@code DateMidnight} from the specified string.
 * <p>
 * This uses {@link ISODateTimeFormat#dateTimeParser()}.
 * 
 * @param str  the string to parse, not null
 * @since 2.0
 */
@FromString
public static DateMidnight parse(String str) {
  return parse(str, ISODateTimeFormat.dateTimeParser().withOffsetParsed());
}

代码示例来源:origin: joda-time/joda-time

DateTimeFormatter dateTimeParser = ISODateTimeFormat.dateTimeParser().withOffsetParsed();
PeriodFormatter periodParser = ISOPeriodFormat.standard();
DateTime start = null;

代码示例来源:origin: JodaOrg/joda-time

DateTimeFormatter dateTimeParser = ISODateTimeFormat.dateTimeParser().withOffsetParsed();
PeriodFormatter periodParser = ISOPeriodFormat.standard();
DateTime start = null;

代码示例来源:origin: prestodb/presto

@ScalarFunction("from_iso8601_timestamp")
@LiteralParameters("x")
@SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE)
public static long fromISO8601Timestamp(ConnectorSession session, @SqlType("varchar(x)") Slice iso8601DateTime)
{
  DateTimeFormatter formatter = ISODateTimeFormat.dateTimeParser()
      .withChronology(getChronology(session.getTimeZoneKey()))
      .withOffsetParsed();
  return packDateTimeWithZone(parseDateTimeHelper(formatter, iso8601DateTime.toStringUtf8()));
}

代码示例来源:origin: prestodb/presto

@Description("parses the specified date/time by the given format")
@ScalarFunction
@LiteralParameters({"x", "y"})
@SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE)
public static long parseDatetime(ConnectorSession session, @SqlType("varchar(x)") Slice datetime, @SqlType("varchar(y)") Slice formatString)
{
  try {
    return packDateTimeWithZone(parseDateTimeHelper(
        DateTimeFormat.forPattern(formatString.toStringUtf8())
            .withChronology(getChronology(session.getTimeZoneKey()))
            .withOffsetParsed()
            .withLocale(session.getLocale()),
        datetime.toStringUtf8()));
  }
  catch (IllegalArgumentException e) {
    throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e);
  }
}

代码示例来源:origin: mulesoft/mule

private DateTime getParsedDateTime(String value) {
  try {
   return ISODateTimeFormat.dateTimeParser().withOffsetParsed().parseDateTime(value);
  } catch (DateTimeParseException e) {
   throw new IllegalArgumentException(format("Could not parse value '%s' according to ISO 8601", value));
  }
 }
}

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * Parses a {@code DateTime} from the specified string.
 * <p>
 * This uses {@link ISODateTimeFormat#dateTimeParser()}.
 * 
 * @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: com.fasterxml.jackson.datatype/jackson-datatype-joda

.append(_format.createFormatter(provider).withOffsetParsed().print(value));
sb = sb.append('[')
    .append(value.getZone())

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * Parses a {@code MutableDateTime} from the specified string.
 * <p>
 * This uses {@link ISODateTimeFormat#dateTimeParser()}.
 * 
 * @param str  the string to parse, not null
 * @since 2.0
 */
@FromString
public static MutableDateTime parse(String str) {
  return parse(str, ISODateTimeFormat.dateTimeParser().withOffsetParsed());
}

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * Parses a {@code DateMidnight} from the specified string.
 * <p>
 * This uses {@link ISODateTimeFormat#dateTimeParser()}.
 * 
 * @param str  the string to parse, not null
 * @since 2.0
 */
@FromString
public static DateMidnight parse(String str) {
  return parse(str, ISODateTimeFormat.dateTimeParser().withOffsetParsed());
}

代码示例来源:origin: com.fasterxml.jackson.datatype/jackson-datatype-joda

/**
 * Accessor used during deserialization.
 */
public DateTimeFormatter createParser(DeserializationContext ctxt)
{
  DateTimeFormatter formatter = _formatter;
  if (!_explicitLocale) {
    Locale loc = ctxt.getLocale();
    if (loc != null && !loc.equals(_locale)) {
      formatter = formatter.withLocale(loc);
    }
  }
  if (!_explicitTimezone) {
    if (shouldAdjustToContextTimeZone(ctxt)) {
      TimeZone tz = ctxt.getTimeZone();
      if (tz != null && !tz.equals(_jdkTimezone)) {
        formatter = formatter.withZone(DateTimeZone.forTimeZone(tz));
      }
    } else {
      formatter = formatter.withOffsetParsed();
    }
  }
  return formatter;
}

相关文章