下面列出了org.joda.time.format.DateTimeFormatter#withChronology ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public String getMessage() {
StringBuffer buf = new StringBuffer(85);
buf.append("The");
String desc = super.getMessage();
if (desc != null) {
buf.append(' ');
buf.append(desc);
}
buf.append(" instant is ");
DateTimeFormatter p = ISODateTimeFormat.dateTime();
p = p.withChronology(getBase());
if (iIsLow) {
buf.append("below the supported minimum of ");
p.printTo(buf, getLowerLimit().getMillis());
} else {
buf.append("above the supported maximum of ");
p.printTo(buf, getUpperLimit().getMillis());
}
buf.append(" (");
buf.append(getBase());
buf.append(')');
return buf.toString();
}
public String getMessage() {
StringBuffer buf = new StringBuffer(85);
buf.append("The");
String desc = super.getMessage();
if (desc != null) {
buf.append(' ');
buf.append(desc);
}
buf.append(" instant is ");
DateTimeFormatter p = ISODateTimeFormat.dateTime();
p = p.withChronology(getBase());
if (iIsLow) {
buf.append("below the supported minimum of ");
p.printTo(buf, getLowerLimit().getMillis());
} else {
buf.append("above the supported maximum of ");
p.printTo(buf, getUpperLimit().getMillis());
}
buf.append(" (");
buf.append(getBase());
buf.append(')');
return buf.toString();
}
/**
* Gets the date format used to string'ify SAML's {@link org.joda.time.DateTime} objects.
*
* @return date format used to string'ify date objects
*/
public static DateTimeFormatter getSAMLDateFormatter() {
if (dateFormatter == null) {
DateTimeFormatter formatter = DateTimeFormat.forPattern(defaultDateFormat);
dateFormatter = formatter.withChronology(ISOChronology.getInstanceUTC());
}
return dateFormatter;
}
@Override
public String asISO8601() {
DateTimeFormatter printer = ISODateTimeFormat.dateTime().withZone(DateTimeZone.UTC);
printer = printer.withChronology(interval.getChronology());
StringBuilder timeString = new StringBuilder(48);
printer.printTo(timeString, interval.getStartMillis());
timeString.append('/');
printer.printTo(timeString, interval.getEndMillis());
return timeString.toString();
}
public static DateTime ConvertFromWebService(String strDate) {
DateTimeFormatter parser1 = new DateTimeFormatterBuilder().append(ISODateTimeFormat.date()).appendLiteral('T')
.append(ISODateTimeFormat.hourMinuteSecond()).appendOptional(fractionElement())
.appendOptional(offsetElement()).toFormatter().withZone(DateTimeZone.UTC);
parser1.withChronology(ISOChronology.getInstanceUTC());
return parser1.parseDateTime(strDate);
}
/**
* 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();
}
/**
* 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();
}
/**
* 変換規則から、{@link DateTimeFormatter}のインスタンスを作成する。
* <p>アノテーション{@link CsvDateTimeFormat}が付与されていない場合は、各種タイプごとの標準の書式で作成する。</p>
* @param field フィールド情報
* @param config システム設定
* @return {@link DateTimeFormatter}のインスタンス。
*/
protected DateTimeFormatter createFormatter(final FieldAccessor field, final Configuration config) {
final Optional<CsvDateTimeFormat> formatAnno = field.getAnnotation(CsvDateTimeFormat.class);
if(!formatAnno.isPresent()) {
return DateTimeFormat.forPattern(getDefaultPattern());
}
String pattern = formatAnno.get().pattern();
if(pattern.isEmpty()) {
pattern = getDefaultPattern();
}
final Locale locale = Utils.getLocale(formatAnno.get().locale());
final DateTimeZone zone = formatAnno.get().timezone().isEmpty() ? DateTimeZone.getDefault()
: DateTimeZone.forTimeZone(TimeZone.getTimeZone(formatAnno.get().timezone()));
final DateTimeFormatter formatter = DateTimeFormat.forPattern(pattern)
.withLocale(locale)
.withZone(zone);
final boolean lenient = formatAnno.get().lenient();
if(lenient) {
Chronology chronology = LenientChronology.getInstance(ISOChronology.getInstance());
return formatter.withChronology(chronology);
} else {
return formatter;
}
}
/**
* Sets the value of the mutable interval from the string.
*
* @param writableInterval the interval to set
* @param object the String to convert, must not be null
* @param chrono the chronology to use, may be null
*/
public void setInto(ReadWritableInterval writableInterval, Object object, Chronology chrono) {
String str = (String) object;
int separator = str.indexOf('/');
if (separator < 0) {
throw new IllegalArgumentException("Format requires a '/' separator: " + str);
}
String leftStr = str.substring(0, separator);
if (leftStr.length() <= 0) {
throw new IllegalArgumentException("Format invalid: " + str);
}
String rightStr = str.substring(separator + 1);
if (rightStr.length() <= 0) {
throw new IllegalArgumentException("Format invalid: " + str);
}
DateTimeFormatter dateTimeParser = ISODateTimeFormat.dateTimeParser();
dateTimeParser = dateTimeParser.withChronology(chrono);
PeriodFormatter periodParser = ISOPeriodFormat.standard();
long startInstant = 0, endInstant = 0;
Period period = null;
Chronology parsedChrono = null;
// before slash
char c = leftStr.charAt(0);
if (c == 'P' || c == 'p') {
period = periodParser.withParseType(getPeriodType(leftStr)).parsePeriod(leftStr);
} else {
DateTime start = dateTimeParser.parseDateTime(leftStr);
startInstant = start.getMillis();
parsedChrono = start.getChronology();
}
// after slash
c = rightStr.charAt(0);
if (c == 'P' || c == 'p') {
if (period != null) {
throw new IllegalArgumentException("Interval composed of two durations: " + str);
}
period = periodParser.withParseType(getPeriodType(rightStr)).parsePeriod(rightStr);
chrono = (chrono != null ? chrono : parsedChrono);
endInstant = chrono.add(period, startInstant, 1);
} else {
DateTime end = dateTimeParser.parseDateTime(rightStr);
endInstant = end.getMillis();
parsedChrono = (parsedChrono != null ? parsedChrono : end.getChronology());
chrono = (chrono != null ? chrono : parsedChrono);
if (period != null) {
startInstant = chrono.add(period, endInstant, -1);
}
}
writableInterval.setInterval(startInstant, endInstant);
writableInterval.setChronology(chrono);
}
/**
* Sets the value of the mutable interval from the string.
*
* @param writableInterval the interval to set
* @param object the String to convert, must not be null
* @param chrono the chronology to use, may be null
*/
public void setInto(ReadWritableInterval writableInterval, Object object, Chronology chrono) {
String str = (String) object;
int separator = str.indexOf('/');
if (separator < 0) {
throw new IllegalArgumentException("Format requires a '/' separator: " + str);
}
String leftStr = str.substring(0, separator);
if (leftStr.length() <= 0) {
throw new IllegalArgumentException("Format invalid: " + str);
}
String rightStr = str.substring(separator + 1);
if (rightStr.length() <= 0) {
throw new IllegalArgumentException("Format invalid: " + str);
}
DateTimeFormatter dateTimeParser = ISODateTimeFormat.dateTimeParser();
dateTimeParser = dateTimeParser.withChronology(chrono);
PeriodFormatter periodParser = ISOPeriodFormat.standard();
long startInstant = 0, endInstant = 0;
Period period = null;
Chronology parsedChrono = null;
// before slash
char c = leftStr.charAt(0);
if (c == 'P' || c == 'p') {
period = periodParser.withParseType(getPeriodType(leftStr)).parsePeriod(leftStr);
} else {
DateTime start = dateTimeParser.parseDateTime(leftStr);
startInstant = start.getMillis();
parsedChrono = start.getChronology();
}
// after slash
c = rightStr.charAt(0);
if (c == 'P' || c == 'p') {
if (period != null) {
throw new IllegalArgumentException("Interval composed of two durations: " + str);
}
period = periodParser.withParseType(getPeriodType(rightStr)).parsePeriod(rightStr);
chrono = (chrono != null ? chrono : parsedChrono);
endInstant = chrono.add(period, startInstant, 1);
} else {
DateTime end = dateTimeParser.parseDateTime(rightStr);
endInstant = end.getMillis();
parsedChrono = (parsedChrono != null ? parsedChrono : end.getChronology());
chrono = (chrono != null ? chrono : parsedChrono);
if (period != null) {
startInstant = chrono.add(period, endInstant, -1);
}
}
writableInterval.setInterval(startInstant, endInstant);
writableInterval.setChronology(chrono);
}
/**
* Sets the date format used to string'ify SAML's date/time objects.
*
* See the
* {@link <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html">SimpleDateFormat</a>}
* documentation for format syntax.
*
* @param format date format used to string'ify date objects
*/
public static void setSAMLDateFormat(String format) {
DateTimeFormatter formatter = DateTimeFormat.forPattern(format);
dateFormatter = formatter.withChronology(ISOChronology.getInstanceUTC());
}