本文整理汇总了Java中org.apache.commons.lang3.time.FastDateFormat.getInstance方法的典型用法代码示例。如果您正苦于以下问题:Java FastDateFormat.getInstance方法的具体用法?Java FastDateFormat.getInstance怎么用?Java FastDateFormat.getInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang3.time.FastDateFormat
的用法示例。
在下文中一共展示了FastDateFormat.getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.apache.commons.lang3.time.FastDateFormat; //导入方法依赖的package包/类
static void init(final Configuration configuration) {
StringCast.datetimeFormat = configuration.getString(
"common.column.datetimeFormat", StringCast.datetimeFormat);
StringCast.dateFormat = configuration.getString(
"common.column.dateFormat", StringCast.dateFormat);
StringCast.timeFormat = configuration.getString(
"common.column.timeFormat", StringCast.timeFormat);
StringCast.extraFormats = configuration.getList(
"common.column.extraFormats", Collections.<String>emptyList(), String.class);
StringCast.timeZone = configuration.getString("common.column.timeZone",
StringCast.timeZone);
StringCast.timeZoner = TimeZone.getTimeZone(StringCast.timeZone);
StringCast.datetimeFormatter = FastDateFormat.getInstance(
StringCast.datetimeFormat, StringCast.timeZoner);
StringCast.dateFormatter = FastDateFormat.getInstance(
StringCast.dateFormat, StringCast.timeZoner);
StringCast.timeFormatter = FastDateFormat.getInstance(
StringCast.timeFormat, StringCast.timeZoner);
StringCast.encoding = configuration.getString("common.column.encoding",
StringCast.encoding);
}
示例2: setup
import org.apache.commons.lang3.time.FastDateFormat; //导入方法依赖的package包/类
@Before
public void setup() {
this.slf4jLogger = mock(org.slf4j.Logger.class);
// Use a special GSON configuration that throws exceptions at the right time for the test.
this.gson = new GsonBuilder().registerTypeAdapterFactory(new TestTypeAdapterFactory()).create();
this.formatter = FastDateFormat.getInstance(dateFormatString);
logger = new StandardJsonLogger(slf4jLogger, formatter, gson, null, null, null) {
@Override
public void log() {
logMessage = formatMessage("INFO");
}
};
}
示例3: filterByDate
import org.apache.commons.lang3.time.FastDateFormat; //导入方法依赖的package包/类
/**
* Default String contains filter processing.
*
* @param item Photo to consider for inclusion.
* @param filterProperty Filter property name used to determine which photo field to compare with.
* @param filterValue Value of the filter.
* @return True if photo should be included in the resultant list to display.
*/
protected boolean filterByDate(T item, String filterProperty, Object filterValue) {
FastDateFormat dateInstance = FastDateFormat.getInstance(MM_DD_YY_PATTERN);
try {
Object fieldValue = PropertyUtils.getNestedProperty(item, filterProperty);
Date theDate = (Date) fieldValue;
String dateStr = dateInstance.format((Date) fieldValue);
if (filterValue == null || (dateInstance.format((Date) fieldValue).contains(filterValue.toString()))) {
return true;
}
} catch (Exception e) {
log.error("Failed to filter. ", e);
}
return false;
}
示例4: convertTest
import org.apache.commons.lang3.time.FastDateFormat; //导入方法依赖的package包/类
@Test
public void convertTest() {
Date now = new Date();
String source = now.toString();
System.out.println(source);
FastDateFormat chinaDate = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss");
FastDateFormat sourceDate = FastDateFormat.getInstance("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
try {
Date object = sourceDate.parse(source);
System.out.println(object);
String format = chinaDate.format(object);
System.out.println(format);
} catch (ParseException e) {
e.printStackTrace();
}
}
示例5: formatDate
import org.apache.commons.lang3.time.FastDateFormat; //导入方法依赖的package包/类
public String formatDate(Date date) {
if (date == null) {
return "";
}
String fmt = "yyyy/MM/dd HH:mm";
Locale locale = Locale.JAPANESE;
// i18nはJavascript側でやる
// RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
// if (requestAttributes instanceof ServletRequestAttributes) {
// HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
// String lang = request.getHeader("Accept-Language");
// if (StringUtils.indexOfIgnoreCase(lang, "ja") != 0) {
// fmt = "d MMM yyyy HH:mm z";
// locale = Locale.ENGLISH;
// }
// }
FastDateFormat sdf = FastDateFormat.getInstance(fmt, AppConfig.JST, locale);
String ret = sdf.format(date);
return ret;
}
示例6: testSetDateTimeFotmat_1
import org.apache.commons.lang3.time.FastDateFormat; //导入方法依赖的package包/类
/**
* Run the void setDateTimeFotmat(FastDateFormat) method test.
*
* @throws Exception
*
* @generatedBy CodePro at 12/15/14 3:52 PM
*/
@Test
public void testSetDateTimeFotmat_1()
throws Exception {
PreferencesBean fixture = new PreferencesBean();
fixture.setDateTimeFotmat(FastDateFormat.getInstance());
fixture.setScreenWidth(1);
fixture.setScreenHeight(1);
fixture.setTimestampFormat(FastDateFormat.getInstance());
FastDateFormat dateTimeFotmat = FastDateFormat.getInstance();
fixture.setDateTimeFotmat(dateTimeFotmat);
// An unexpected exception was thrown in user code while executing this test:
// java.lang.NoClassDefFoundError: com_cenqua_clover/CoverageRecorder
// at com.intuit.tank.PreferencesBean.<init>(PreferencesBean.java:179)
}
示例7: testSetTimestampFormat_1
import org.apache.commons.lang3.time.FastDateFormat; //导入方法依赖的package包/类
/**
* Run the void setTimestampFormat(FastDateFormat) method test.
*
* @throws Exception
*
* @generatedBy CodePro at 12/15/14 3:52 PM
*/
@Test
public void testSetTimestampFormat_1()
throws Exception {
PreferencesBean fixture = new PreferencesBean();
fixture.setDateTimeFotmat(FastDateFormat.getInstance());
fixture.setScreenWidth(1);
fixture.setScreenHeight(1);
fixture.setTimestampFormat(FastDateFormat.getInstance());
FastDateFormat timestampFormat = FastDateFormat.getInstance();
fixture.setTimestampFormat(timestampFormat);
// An unexpected exception was thrown in user code while executing this test:
// java.lang.NoClassDefFoundError: com_cenqua_clover/CoverageRecorder
// at com.intuit.tank.PreferencesBean.<init>(PreferencesBean.java:179)
}
示例8: parseDate
import org.apache.commons.lang3.time.FastDateFormat; //导入方法依赖的package包/类
/**
* Adapted from DateUtils to support Timezones, and parse ical dates into {@link java.util.Date}.
* Note: Replace FastDateFormat to java.time, when shifting to Java 8 or higher.
*
* @param str Date representation in String.
* @param patterns Patterns to parse the date against
* @param _timeZone Timezone of the Date.
* @return <code>java.util.Date</code> representation of string or
* <code>null</code> if the Date could not be parsed.
*/
public Date parseDate(String str, String[] patterns, TimeZone _timeZone) {
FastDateFormat parser;
Locale locale = WebSession.get().getLocale();
TimeZone timeZone = str.endsWith("Z") ? TimeZone.getTimeZone("UTC") : _timeZone;
ParsePosition pos = new ParsePosition(0);
for (String pattern : patterns) {
parser = FastDateFormat.getInstance(pattern, timeZone, locale);
pos.setIndex(0);
Date date = parser.parse(str, pos);
if (date != null && pos.getIndex() == str.length()) {
return date;
}
}
log.error("Unable to parse the date: " + str + " at " + -1);
return null;
}
示例9: write
import org.apache.commons.lang3.time.FastDateFormat; //导入方法依赖的package包/类
@Override
public void write(final OutputStream output) throws IOException {
final Writer writer = new BufferedWriter(new OutputStreamWriter(output, "cp1252"));
final FastDateFormat df = FastDateFormat.getInstance("yyyy/MM/dd HH:mm:ss");
// Write headers
writeHeaders(writer);
// Write data
writeData(writer, df);
writer.flush();
}
示例10: writeReport
import org.apache.commons.lang3.time.FastDateFormat; //导入方法依赖的package包/类
/**
* Write all execution related to given subscription, from the oldest to the
* newest.
*/
private void writeReport(final Subscription subscription, final OutputStream output) throws IOException {
final Writer writer = new BufferedWriter(new OutputStreamWriter(output, "cp1252"));
final FastDateFormat df = FastDateFormat.getInstance("yyyy/MM/dd HH:mm:ss");
writer.write("dateHMS;timestamp;operation;subscription;project;projectKey;projectName;node;trigger;succeed");
for (final VmExecution execution : vmExecutionRepository.findAllBy("subscription.id", subscription.getId())) {
writer.write('\n');
writer.write(df.format(execution.getDate()));
writer.write(';');
writer.write(String.valueOf(execution.getDate().getTime()));
writer.write(';');
writer.write(execution.getOperation().name());
writer.write(';');
writer.write(String.valueOf(subscription.getId()));
writer.write(';');
writer.write(String.valueOf(subscription.getProject().getId()));
writer.write(';');
writer.write(subscription.getProject().getPkey());
writer.write(';');
writer.write(subscription.getProject().getName().replaceAll("\"", "'"));
writer.write(';');
writer.write(subscription.getNode().getId());
writer.write(';');
writer.write(execution.getTrigger());
writer.write(';');
writer.write(String.valueOf(execution.isSucceed()));
}
// Ensure buffer is flushed
writer.flush();
}
示例11: isDate
import org.apache.commons.lang3.time.FastDateFormat; //导入方法依赖的package包/类
/**
* @param date 格式为:yyyy-MM-dd HH:mm:ss {@link String}
* @return boolean
* @description 判断是否为正确日期
*/
public static boolean isDate(String date) {
FastDateFormat format = FastDateFormat.getInstance(PATTERN_HAVE_TIME);
try {
return format.format(format.parse(date)).equals(date);
} catch (ParseException e) {
return false;
}
}
示例12: getCurDate
import org.apache.commons.lang3.time.FastDateFormat; //导入方法依赖的package包/类
/***
* 格式化时间
* @param date yyyy-MM-dd
* @return {@link Date}
*/
public static Date getCurDate(String date, String pattern) {
FastDateFormat format = FastDateFormat.getInstance(pattern);
try {
return format.parse(date);
} catch (ParseException e) {
log.error(e.getMessage());
return null;
}
}
示例13: testGetValue
import org.apache.commons.lang3.time.FastDateFormat; //导入方法依赖的package包/类
/**
* Simple date format of static context.
*/
@Test
public void testGetValue() throws ParseException {
final Deque<Object> contextData = new LinkedList<>();
final SystemUser systemUser = new SystemUser();
contextData.add(systemUser);
final FastDateFormat df = FastDateFormat.getInstance("yyyy/MM/dd", null, null);
Assert.assertEquals("2014/05/30", new FormatProcessor<>(df, DateUtils.parseDate("2014/05/30", "yyyy/MM/dd")).getValue(contextData));
}
示例14: testGetItemValue
import org.apache.commons.lang3.time.FastDateFormat; //导入方法依赖的package包/类
/**
* Simple date format of dynamic context.
*/
@Test
public void testGetItemValue() throws ParseException {
final Deque<Object> contextData = new LinkedList<>();
contextData.add(DateUtils.parseDate("2014/05/30", "yyyy/MM/dd"));
final FastDateFormat df = FastDateFormat.getInstance("yyyy/MM/dd", null, null);
Assert.assertEquals("2014/05/30", new FormatProcessor<>(df).getValue(contextData));
}
示例15: serialize
import org.apache.commons.lang3.time.FastDateFormat; //导入方法依赖的package包/类
@Override
public void serialize(Date date, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException {
if (date!=null) {
Locale locale = LocaleContextHolder.getLocale();
TimeZone timeZone = LocaleContextHolder.getTimeZone();
FastDateFormat fastDateFormat = FastDateFormat.getInstance("yyyy-MM-dd", timeZone, locale);
jsonGenerator.writeString(fastDateFormat.format(date));
} else {
jsonGenerator.writeString("");
}
}