本文整理汇总了Java中org.joda.time.format.DateTimeFormatterBuilder类的典型用法代码示例。如果您正苦于以下问题:Java DateTimeFormatterBuilder类的具体用法?Java DateTimeFormatterBuilder怎么用?Java DateTimeFormatterBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DateTimeFormatterBuilder类属于org.joda.time.format包,在下文中一共展示了DateTimeFormatterBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: TikaPoweredMetadataExtracter
import org.joda.time.format.DateTimeFormatterBuilder; //导入依赖的package包/类
public TikaPoweredMetadataExtracter(String extractorContext, HashSet<String> supportedMimeTypes, HashSet<String> supportedEmbedMimeTypes)
{
super(supportedMimeTypes, supportedEmbedMimeTypes);
this.extractorContext = extractorContext;
// TODO Once TIKA-451 is fixed this list will get nicer
DateTimeParser[] parsersUTC = {
DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss'Z'").getParser(),
DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZ").getParser()
};
DateTimeParser[] parsers = {
DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss").getParser(),
DateTimeFormat.forPattern("yyyy-MM-dd").getParser(),
DateTimeFormat.forPattern("yyyy/MM/dd HH:mm:ss").getParser(),
DateTimeFormat.forPattern("yyyy/MM/dd").getParser(),
DateTimeFormat.forPattern("EEE MMM dd hh:mm:ss zzz yyyy").getParser()
};
this.tikaUTCDateFormater = new DateTimeFormatterBuilder().append(null, parsersUTC).toFormatter().withZone(DateTimeZone.UTC);
this.tikaDateFormater = new DateTimeFormatterBuilder().append(null, parsers).toFormatter();
}
示例2: dateTime
import org.joda.time.format.DateTimeFormatterBuilder; //导入依赖的package包/类
public static DateTimeFormatter dateTime() {
if (hl7 == null) {
hl7 = new DateTimeFormatterBuilder()
.appendYear(4, 4)
.appendMonthOfYear(2)
.appendDayOfMonth(2)
.appendHourOfDay(2)
.appendMinuteOfHour(2)
.appendSecondOfMinute(2)
.appendLiteral('.')
.appendMillisOfSecond(3)
.appendTimeZoneOffset(null, false, 2, 2)
.toFormatter();
}
return hl7;
}
示例3: TimeConverter
import org.joda.time.format.DateTimeFormatterBuilder; //导入依赖的package包/类
/**
* creates instance with specific rounding.
*
* @param rounding
* rounding
*/
public TimeConverter(Rounding rounding) {
this.rounding = rounding;
char separator = DecimalFormatSymbols.getInstance().getDecimalSeparator();
DateTimeFormatterBuilder parseBuilder = new DateTimeFormatterBuilder().appendHourOfDay(2).appendLiteral(':')
.appendMinuteOfHour(2);
parseBuilder.appendOptional(new DateTimeFormatterBuilder().appendLiteral(separator)
.appendFractionOfMinute(0, 1).toParser());
this.parse = parseBuilder.toFormatter();
DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder().appendHourOfDay(1).appendLiteral(':')
.appendMinuteOfHour(2);
DateTimeFormatterBuilder builderFull = new DateTimeFormatterBuilder().appendHourOfDay(2).appendLiteral(':')
.appendMinuteOfHour(2);
if (rounding != Rounding.MINUTE) {
builder.appendLiteral(separator).appendFractionOfMinute(1, 1);
builderFull.appendLiteral(separator).appendFractionOfMinute(1, 1);
}
this.print = builder.toFormatter();
this.printFull = builderFull.toFormatter();
this.duration = new DecimalFormat("###.#");
this.printXml = ISODateTimeFormat.hourMinuteSecond();
}
示例4: onCreate
import org.joda.time.format.DateTimeFormatterBuilder; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Crashlytics.start(this);
EventBus.getDefault().register(this);
connection = getConnection();
setContentView(R.layout.activity_main);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
ButterKnife.inject(this, this);
DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
formatter = builder.appendHourOfDay(2).appendLiteral(':')
.appendMinuteOfHour(2).appendLiteral(':')
.appendSecondOfMinute(2).toFormatter();
textView.setMovementMethod(new ScrollingMovementMethod());
textView.setTypeface(Typeface.MONOSPACE);
if (savedInstanceState == null) {
Intent intent = new Intent(this, BackServiceImpl.class);
startService(intent);
} else {
String logText = savedInstanceState.getString(LOG_EXTRA);
textView.setText(logText);
}
}
示例5: initialValue
import org.joda.time.format.DateTimeFormatterBuilder; //导入依赖的package包/类
@Override
protected DateTimeFormatter initialValue() {
return new DateTimeFormatterBuilder()
.append(DateTimeFormat.forPattern("yyyy-MM-dd"))
.appendOptional(
new DateTimeFormatterBuilder()
.appendLiteral('T')
.appendOptional(
new DateTimeFormatterBuilder()
.append(DateTimeFormat.forPattern("HH"))
.appendOptional(
new DateTimeFormatterBuilder()
.append(DateTimeFormat.forPattern(":mm"))
.appendOptional(
new DateTimeFormatterBuilder()
.append(DateTimeFormat.forPattern(":ss"))
.toParser())
.toParser())
.toParser())
.toParser())
.toFormatter();
}
示例6: onCreate
import org.joda.time.format.DateTimeFormatterBuilder; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
setData(getArguments());
}
DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
mFormatter = builder
.appendYear(4, 4).appendLiteral("-")
.appendMonthOfYear(2).appendLiteral("-")
.appendDayOfMonth(2).appendLiteral(" at ")
.appendHourOfDay(2).appendLiteral(":")
.appendMinuteOfHour(2)
.toFormatter();
}
示例7: buildDTFormatter
import org.joda.time.format.DateTimeFormatterBuilder; //导入依赖的package包/类
/**
*
* @return a formatter for common ISO strings
*/
private DateTimeFormatter buildDTFormatter() {
//build a parser for time stamps
return new DateTimeFormatterBuilder()
.appendYear(4, 4) //4 digit year (YYYY)
.appendLiteral("-")
.appendMonthOfYear(2) //2 digit month (MM)
.appendLiteral("-")
.appendDayOfMonth(2) //2 digit day (DD)
.appendLiteral("T")
.appendHourOfDay(2) //2 digit hour (hh)
.appendLiteral(":")
.appendMinuteOfHour(2) //2 digit minute (mm)
.appendLiteral(":")
.appendSecondOfMinute(2)//2 digit second (ss)
//optional 3 digit milliseconds of second
.appendOptional(new DateTimeFormatterBuilder()
.appendLiteral(".")
.appendMillisOfSecond(3)
.toParser())
//optional time zone offset as (+|-)hh:mm
.appendOptional(new DateTimeFormatterBuilder()
.appendTimeZoneOffset("", true, 2, 2)
.toParser())
.toFormatter();
}
示例8: buildDTFormatter
import org.joda.time.format.DateTimeFormatterBuilder; //导入依赖的package包/类
/**
*
* @return a formatter for common ISO strings
*/
private DateTimeFormatter buildDTFormatter() {
//build a parser for time stamps
return new DateTimeFormatterBuilder()
.appendYear(4, 4) //4 digit year (YYYY)
.appendLiteral("-")
.appendMonthOfYear(2) //2 digit month (MM)
.appendLiteral("-")
.appendDayOfMonth(2) //2 digit day (DD)
.appendLiteral("T")
.appendHourOfDay(2) //2 digit hour (hh)
.appendLiteral(":")
.appendMinuteOfHour(2) //2 digit minute (mm)
.appendLiteral(":")
.appendSecondOfMinute(2)//2 digit second (ss)
//optional 3 digit milliseconds of second
.appendOptional(new DateTimeFormatterBuilder()
.appendLiteral(".")
.appendMillisOfSecond(3)
.toParser())
//optional time zone offset as (+|-)hh:mm
.appendOptional(new DateTimeFormatterBuilder()
.appendTimeZoneOffset("", true, 2, 2)
.toParser())
.toFormatter();
}
示例9: toUIString
import org.joda.time.format.DateTimeFormatterBuilder; //导入依赖的package包/类
public String toUIString()
{
DateTimeFormatter DF = new DateTimeFormatterBuilder()
.appendYear(4, 4)
.appendLiteral('-')
.appendMonthOfYear(1)
.appendLiteral('-')
.appendDayOfMonth(1)
.appendLiteral(" ")
.appendHourOfDay(2)
.appendLiteral(':')
.appendMinuteOfHour(2)
.appendLiteral(':')
.appendSecondOfMinute(2)
.appendLiteral('.')
.appendMillisOfSecond(1)
.toFormatter();
return DF.print( toDateTime());
}
示例10: toUIString
import org.joda.time.format.DateTimeFormatterBuilder; //导入依赖的package包/类
public String toUIString()
{
DateTimeFormatter DF = new DateTimeFormatterBuilder()
.appendYear(4, 4)
.appendLiteral('-')
.appendMonthOfYear(1)
.appendLiteral('-')
.appendDayOfMonth(1)
.appendLiteral(" ")
.appendHourOfDay(2)
.appendLiteral(':')
.appendMinuteOfHour(2)
.appendLiteral(':')
.appendSecondOfMinute(2)
.appendLiteral('.')
.appendMillisOfSecond(1)
.toFormatter();
final String start = DF.print( this.start.toDateTime());
final String end = DF.print( this.end.toDateTime());
return start+" - "+end+" [ "+getDurationInMilliseconds()+" ms ]";
}
示例11: getStrictStandardDateFormatter
import org.joda.time.format.DateTimeFormatterBuilder; //导入依赖的package包/类
public static FormatDateTimeFormatter getStrictStandardDateFormatter() {
// 2014/10/10
DateTimeFormatter shortFormatter = new DateTimeFormatterBuilder()
.appendFixedDecimal(DateTimeFieldType.year(), 4)
.appendLiteral('/')
.appendFixedDecimal(DateTimeFieldType.monthOfYear(), 2)
.appendLiteral('/')
.appendFixedDecimal(DateTimeFieldType.dayOfMonth(), 2)
.toFormatter()
.withZoneUTC();
// 2014/10/10 12:12:12
DateTimeFormatter longFormatter = new DateTimeFormatterBuilder()
.appendFixedDecimal(DateTimeFieldType.year(), 4)
.appendLiteral('/')
.appendFixedDecimal(DateTimeFieldType.monthOfYear(), 2)
.appendLiteral('/')
.appendFixedDecimal(DateTimeFieldType.dayOfMonth(), 2)
.appendLiteral(' ')
.appendFixedSignedDecimal(DateTimeFieldType.hourOfDay(), 2)
.appendLiteral(':')
.appendFixedSignedDecimal(DateTimeFieldType.minuteOfHour(), 2)
.appendLiteral(':')
.appendFixedSignedDecimal(DateTimeFieldType.secondOfMinute(), 2)
.toFormatter()
.withZoneUTC();
DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder().append(longFormatter.withZone(DateTimeZone.UTC).getPrinter(), new DateTimeParser[]{longFormatter.getParser(), shortFormatter.getParser(), new EpochTimeParser(true)});
return new FormatDateTimeFormatter("yyyy/MM/dd HH:mm:ss||yyyy/MM/dd||epoch_millis", builder.toFormatter().withZone(DateTimeZone.UTC), Locale.ROOT);
}
示例12: testMultiParsers
import org.joda.time.format.DateTimeFormatterBuilder; //导入依赖的package包/类
public void testMultiParsers() {
DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
DateTimeParser[] parsers = new DateTimeParser[3];
parsers[0] = DateTimeFormat.forPattern("MM/dd/yyyy").withZone(DateTimeZone.UTC).getParser();
parsers[1] = DateTimeFormat.forPattern("MM-dd-yyyy").withZone(DateTimeZone.UTC).getParser();
parsers[2] = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss").withZone(DateTimeZone.UTC).getParser();
builder.append(DateTimeFormat.forPattern("MM/dd/yyyy").withZone(DateTimeZone.UTC).getPrinter(), parsers);
DateTimeFormatter formatter = builder.toFormatter();
formatter.parseMillis("2009-11-15 14:12:12");
}
示例13: getDateTimeFormatter
import org.joda.time.format.DateTimeFormatterBuilder; //导入依赖的package包/类
public static DateTimeFormatter getDateTimeFormatter() {
if (dateTimeTZFormat == null) {
DateTimeFormatter dateFormatter = DateTimeFormat.forPattern("yyyy-MM-dd");
DateTimeParser optionalTime = DateTimeFormat.forPattern(" HH:mm:ss").getParser();
DateTimeParser optionalSec = DateTimeFormat.forPattern(".SSS").getParser();
DateTimeParser optionalZone = DateTimeFormat.forPattern(" ZZZ").getParser();
dateTimeTZFormat = new DateTimeFormatterBuilder().append(dateFormatter).appendOptional(optionalTime).appendOptional(optionalSec).appendOptional(optionalZone).toFormatter();
}
return dateTimeTZFormat;
}
示例14: getTimeFormatter
import org.joda.time.format.DateTimeFormatterBuilder; //导入依赖的package包/类
public static DateTimeFormatter getTimeFormatter() {
if (timeFormat == null) {
DateTimeFormatter timeFormatter = DateTimeFormat.forPattern("HH:mm:ss");
DateTimeParser optionalSec = DateTimeFormat.forPattern(".SSS").getParser();
timeFormat = new DateTimeFormatterBuilder().append(timeFormatter).appendOptional(optionalSec).toFormatter();
}
return timeFormat;
}
示例15: validateInputDate
import org.joda.time.format.DateTimeFormatterBuilder; //导入依赖的package包/类
/**
*
* @param finishDate
* @return
* @throws Exception
*/
public static final DateTime validateInputDate(final String date, final String permittedDateFormats) throws Exception {
logger.debug("----Inside validateInputDate, date: " + date + " & permittedDateFormats: " + permittedDateFormats);
/* Seperate all the formats */
final String[] defaultDateFormats = permittedDateFormats.split(",");
/* Create array for all date parsing formats */
final DateTimeParser[] dateTimeParser = new DateTimeParser[defaultDateFormats.length];
/* Parse with individual formats */
for (int i = 0; i < defaultDateFormats.length; i++) {
/* If format is valid */
if (defaultDateFormats[i] != null && !"".equals(defaultDateFormats[i])) {
/* Create new parser for each format */
dateTimeParser[i] = DateTimeFormat.forPattern(defaultDateFormats[i].trim()).getParser();
}
}
/* Final date formater builder */
final DateTimeFormatter dateTimeFormatter = new DateTimeFormatterBuilder().append(null, dateTimeParser).toFormatter();
/* Parse user supplied date */
final DateTime updatedDate = dateTimeFormatter.parseDateTime(date);
logger.debug("----Inside validateInputDate, updated date: " + updatedDate);
/* Return updated date */
return updatedDate;
}