本文整理了Java中org.joda.time.format.DateTimeFormatter.withChronology()
方法的一些代码示例,展示了DateTimeFormatter.withChronology()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DateTimeFormatter.withChronology()
方法的具体详情如下:
包路径:org.joda.time.format.DateTimeFormatter
类名称:DateTimeFormatter
方法名:withChronology
[英]Returns a new formatter that will use the specified chronology in preference to that of the printed object, or ISO on a parse.
When printing, this chronolgy will be used in preference to the chronology from the datetime that would otherwise be used.
When parsing, this chronology will be set on the parsed datetime.
A null chronology means no-override. If both an override chronology and an override zone are set, the override zone will take precedence over the zone in the chronology.
[中]返回一个新的格式化程序,该格式化程序将优先使用指定的时间顺序,而不是打印对象的时间顺序,或在解析时使用ISO。
打印时,此计时将优先于使用datetime的年表。
解析时,将在解析的日期时间上设置此年表。
空的时间顺序表示没有覆盖。如果同时设置了替代年表和替代分区,则替代分区将优先于年表中的分区。
代码示例来源:origin: prestodb/presto
@Deprecated
public static String printTimestampWithoutTimeZone(TimeZoneKey timeZoneKey, long timestamp)
{
return LEGACY_TIMESTAMP_WITHOUT_TIME_ZONE_FORMATTER.withChronology(getChronology(timeZoneKey)).print(timestamp);
}
代码示例来源:origin: apache/incubator-druid
private UtcFormatter(final DateTimeFormatter innerFormatter)
{
this.innerFormatter = innerFormatter.withChronology(ISOChronology.getInstanceUTC());
}
代码示例来源:origin: prestodb/presto
public static String printTimestampWithTimeZone(long timestampWithTimeZone)
{
ISOChronology chronology = unpackChronology(timestampWithTimeZone);
long millis = unpackMillisUtc(timestampWithTimeZone);
return TIMESTAMP_WITH_TIME_ZONE_FORMATTER.withChronology(chronology).print(millis);
}
代码示例来源:origin: prestodb/presto
/**
* Parse a string (optionally containing a zone) as a value of TIMESTAMP type.
* If the string doesn't specify a zone, it is interpreted in {@code timeZoneKey} zone.
*
* @return stack representation of legacy TIMESTAMP type
*/
@Deprecated
public static long parseTimestampWithoutTimeZone(TimeZoneKey timeZoneKey, String value)
{
return TIMESTAMP_WITH_OR_WITHOUT_TIME_ZONE_FORMATTER.withChronology(getChronology(timeZoneKey)).parseMillis(value);
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Get the DateTimeFormatter with the this context's settings
* applied to the base {@code formatter}.
* @param formatter the base formatter that establishes default
* formatting rules, generally context-independent
* @return the contextual DateTimeFormatter
*/
public DateTimeFormatter getFormatter(DateTimeFormatter formatter) {
if (this.chronology != null) {
formatter = formatter.withChronology(this.chronology);
}
if (this.timeZone != null) {
formatter = formatter.withZone(this.timeZone);
}
else {
LocaleContext localeContext = LocaleContextHolder.getLocaleContext();
if (localeContext instanceof TimeZoneAwareLocaleContext) {
TimeZone timeZone = ((TimeZoneAwareLocaleContext) localeContext).getTimeZone();
if (timeZone != null) {
formatter = formatter.withZone(DateTimeZone.forTimeZone(timeZone));
}
}
}
return formatter;
}
代码示例来源:origin: prestodb/presto
private static Slice dateFormat(ISOChronology chronology, Locale locale, long timestamp, Slice formatString)
{
DateTimeFormatter formatter = DATETIME_FORMATTER_CACHE.get(formatString)
.withChronology(chronology)
.withLocale(locale);
return utf8Slice(formatter.print(timestamp));
}
代码示例来源:origin: joda-time/joda-time
/**
* Gets the millis, which is the ISO parsed string value.
*
* @param object the String to convert, must not be null
* @param chrono the chronology to use, non-null result of getChronology
* @return the millisecond value
* @throws IllegalArgumentException if the value if invalid
*/
public long getInstantMillis(Object object, Chronology chrono) {
String str = (String) object;
DateTimeFormatter p = ISODateTimeFormat.dateTimeParser();
return p.withChronology(chrono).parseMillis(str);
}
代码示例来源:origin: prestodb/presto
private static Slice formatDatetime(ISOChronology chronology, Locale locale, long timestamp, Slice formatString)
{
try {
return utf8Slice(DateTimeFormat.forPattern(formatString.toStringUtf8())
.withChronology(chronology)
.withLocale(locale)
.print(timestamp));
}
catch (IllegalArgumentException e) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e);
}
}
代码示例来源:origin: prestodb/presto
/**
* Parse a string (optionally containing a zone) as a value of either TIMESTAMP or TIMESTAMP WITH TIME ZONE type.
* If the string doesn't specify a zone, it is interpreted in {@code timeZoneKey} zone.
*
* @return stack representation of legacy TIMESTAMP or TIMESTAMP WITH TIME ZONE type, depending on input
*/
@Deprecated
public static long parseTimestampLiteral(TimeZoneKey timeZoneKey, String value)
{
try {
DateTime dateTime = TIMESTAMP_WITH_TIME_ZONE_FORMATTER.parseDateTime(value);
return packDateTimeWithZone(dateTime);
}
catch (RuntimeException e) {
return LEGACY_TIMESTAMP_WITHOUT_TIME_ZONE_FORMATTER.withChronology(getChronology(timeZoneKey)).parseMillis(value);
}
}
代码示例来源:origin: JodaOrg/joda-time
/**
* Gets the millis, which is the ISO parsed string value.
*
* @param object the String to convert, must not be null
* @param chrono the chronology to use, non-null result of getChronology
* @return the millisecond value
* @throws IllegalArgumentException if the value if invalid
*/
public long getInstantMillis(Object object, Chronology chrono) {
String str = (String) object;
DateTimeFormatter p = ISODateTimeFormat.dateTimeParser();
return p.withChronology(chrono).parseMillis(str);
}
代码示例来源: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: prestodb/presto
@ScalarFunction("to_iso8601")
@SqlType("varchar(16)")
// Standard format is YYYY-MM-DD, which gives up to 10 characters.
// However extended notation with format ±(Y)+-MM-DD is also acceptable and as the maximum year
// represented by 64bits timestamp is ~584944387 it may require up to 16 characters to represent a date.
public static Slice toISO8601FromDate(ConnectorSession session, @SqlType(StandardTypes.DATE) long date)
{
DateTimeFormatter formatter = ISODateTimeFormat.date()
.withChronology(UTC_CHRONOLOGY);
return utf8Slice(formatter.print(DAYS.toMillis(date)));
}
代码示例来源:origin: joda-time/joda-time
/**
* Output a string in ISO8601 interval format.
* <p>
* From version 2.1, the string includes the time zone offset.
*
* @return re-parsable string (in the default zone)
*/
public String toString() {
DateTimeFormatter printer = ISODateTimeFormat.dateTime();
printer = printer.withChronology(getChronology());
StringBuffer buf = new StringBuffer(48);
printer.printTo(buf, getStartMillis());
buf.append('/');
printer.printTo(buf, getEndMillis());
return buf.toString();
}
代码示例来源:origin: JodaOrg/joda-time
/**
* Output a string in ISO8601 interval format.
* <p>
* From version 2.1, the string includes the time zone offset.
*
* @return re-parsable string (in the default zone)
*/
public String toString() {
DateTimeFormatter printer = ISODateTimeFormat.dateTime();
printer = printer.withChronology(getChronology());
StringBuffer buf = new StringBuffer(48);
printer.printTo(buf, getStartMillis());
buf.append('/');
printer.printTo(buf, getEndMillis());
return buf.toString();
}
代码示例来源:origin: prestodb/presto
@ScalarFunction("to_iso8601")
@SqlType("varchar(35)")
// YYYY-MM-DDTHH:MM:SS.mmm+HH:MM is a standard notation, and it requires 29 characters.
// However extended notation with format ±(Y)+-MM-DDTHH:MM:SS.mmm+HH:MM is also acceptable and as
// the maximum year represented by 64bits timestamp is ~584944387 it may require up to 35 characters.
public static Slice toISO8601FromTimestamp(ConnectorSession session, @SqlType(StandardTypes.TIMESTAMP) long timestamp)
{
if (session.isLegacyTimestamp()) {
DateTimeFormatter formatter = ISODateTimeFormat.dateTime()
.withChronology(getChronology(session.getTimeZoneKey()));
return utf8Slice(formatter.print(timestamp));
}
else {
DateTimeFormatter formatter = ISODateTimeFormat.dateHourMinuteSecondMillis()
.withChronology(UTC_CHRONOLOGY);
return utf8Slice(formatter.print(timestamp));
}
}
代码示例来源:origin: prestodb/presto
@ScalarFunction("from_iso8601_date")
@LiteralParameters("x")
@SqlType(StandardTypes.DATE)
public static long fromISO8601Date(ConnectorSession session, @SqlType("varchar(x)") Slice iso8601DateTime)
{
DateTimeFormatter formatter = ISODateTimeFormat.dateElementParser()
.withChronology(UTC_CHRONOLOGY);
DateTime dateTime = parseDateTimeHelper(formatter, iso8601DateTime.toStringUtf8());
return MILLISECONDS.toDays(dateTime.getMillis());
}
代码示例来源:origin: prestodb/presto
@ScalarFunction("to_iso8601")
@SqlType("varchar(35)")
// YYYY-MM-DDTHH:MM:SS.mmm+HH:MM is a standard notation, and it requires 29 characters.
// However extended notation with format ±(Y)+-MM-DDTHH:MM:SS.mmm+HH:MM is also acceptable and as
// the maximum year represented by 64bits timestamp is ~584944387 it may require up to 35 characters.
public static Slice toISO8601FromTimestampWithTimeZone(@SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) long timestampWithTimeZone)
{
long millisUtc = unpackMillisUtc(timestampWithTimeZone);
DateTimeFormatter formatter = ISODateTimeFormat.dateTime()
.withChronology(getChronology(unpackZoneKey(timestampWithTimeZone)));
return utf8Slice(formatter.print(millisUtc));
}
代码示例来源: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: prestodb/presto
@ScalarFunction
@LiteralParameters({"x", "y"})
@SqlType(StandardTypes.TIMESTAMP)
public static long dateParse(ConnectorSession session, @SqlType("varchar(x)") Slice dateTime, @SqlType("varchar(y)") Slice formatString)
{
DateTimeFormatter formatter = DATETIME_FORMATTER_CACHE.get(formatString)
.withChronology(session.isLegacyTimestamp() ? getChronology(session.getTimeZoneKey()) : UTC_CHRONOLOGY)
.withLocale(session.getLocale());
try {
return formatter.parseMillis(dateTime.toStringUtf8());
}
catch (IllegalArgumentException e) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e);
}
}
内容来源于网络,如有侵权,请联系作者删除!