本文整理汇总了Java中org.apache.commons.lang.time.FastDateFormat.format方法的典型用法代码示例。如果您正苦于以下问题:Java FastDateFormat.format方法的具体用法?Java FastDateFormat.format怎么用?Java FastDateFormat.format使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang.time.FastDateFormat
的用法示例。
在下文中一共展示了FastDateFormat.format方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: formatdate
import org.apache.commons.lang.time.FastDateFormat; //导入方法依赖的package包/类
public String formatdate(String pattern) {
FastDateFormat formatter = FastDateFormat.getInstance(pattern);
if (value instanceof Date) {
return formatter.format((Date) value);
} else if (value != null) {
String text = value != null ? value.toString() : "";
Date dateToParse = parseDateFromText(pattern, text);
if (dateToParse != null) {
return formatter.format((Date) value);
} else {
return "Not a datetime";
}
} else {
return "";
}
}
示例2: buildShowDate
import org.apache.commons.lang.time.FastDateFormat; //导入方法依赖的package包/类
/**
* 构建显示日期
*
* @param timeUnit
* @param dayFormat
* @since 2015-7-28 by wangchongjie
*/
protected void buildShowDate(int timeUnit, FastDateFormat dayFormat) {
if (this.unixTime > 0) {
Date d = new Date();
d.setTime(this.unixTime * 1000L);
if (OlapConstants.TU_DAY == timeUnit) { // 天粒度
this.showDate = dayFormat.format(d);
} else if (OlapConstants.TU_HOUR == timeUnit) {
this.showDate = sd3.format(d);
} else {
this.showDate = dayFormat.format(d);
}
}
}
示例3: main
import org.apache.commons.lang.time.FastDateFormat; //导入方法依赖的package包/类
@Test
public void main() {
// 使用FastDateFormat
FastDateFormat format = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss");
String dateStr = format.format(new Date());
// 使用DateFormatUtils,底层还是用的FastDateFormat
String t = DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss");
System.out.println(dateStr);
System.out.println(t);
}
示例4: formatDateNullSafe
import org.apache.commons.lang.time.FastDateFormat; //导入方法依赖的package包/类
/**
* Format date null safe.
*
* @param format the format
* @param value the value
* @return the string
*/
private String formatDateNullSafe(String format, E value) {
if (value == null) {
return null;
}
FastDateFormat df = FastDateFormat.getInstance(format);
return df.format(value);
}
示例5: mysqlConvertToObjectTest
import org.apache.commons.lang.time.FastDateFormat; //导入方法依赖的package包/类
@Test
public void mysqlConvertToObjectTest() throws Exception {
ColumnMetadata colMd = new ColumnMetadata();
FastDateFormat fdfDate = FastDateFormat.getInstance(MysqlNativeConstants.MYSQL_DATE_FORMAT);
FastDateFormat fdfDateTime = FastDateFormat.getInstance(MysqlNativeConstants.MYSQL_DATETIME_FORMAT);
FastDateFormat fdfTime = FastDateFormat.getInstance(MysqlNativeConstants.MYSQL_TIME_FORMAT);
FastDateFormat fdfTimestamp = FastDateFormat.getInstance(MysqlNativeConstants.MYSQL_TIMESTAMP_FORMAT);
for (Pair<MyFieldType, Object> expValue : expValuesMysql) {
DataTypeValueFunc dtvf = DBTypeBasedUtils.getMysqlTypeFunc(expValue.getFirst());
assertNotNull("Couldn't find function for " + expValue.getFirst(), dtvf);
if ( expValue.getSecond() != null ) {
String value;
if ( MyFieldType.FIELD_TYPE_DATE.equals(expValue.getFirst()) ) {
value = fdfDate.format(expValue.getSecond());
} else if ( MyFieldType.FIELD_TYPE_DATETIME.equals(expValue.getFirst()) ) {
value = fdfDateTime.format(expValue.getSecond());
} else if ( MyFieldType.FIELD_TYPE_TIME.equals(expValue.getFirst()) ) {
value = fdfTime.format(expValue.getSecond());
} else if ( MyFieldType.FIELD_TYPE_TIMESTAMP.equals(expValue.getFirst()) ) {
value = fdfTimestamp.format(expValue.getSecond());
} else if (MyFieldType.FIELD_TYPE_BIT.equals(expValue.getFirst())) {
value = new String((byte[]) expValue.getSecond(), CharsetUtil.ISO_8859_1);
} else {
value = expValue.getSecond().toString();
}
Object valueObj = dtvf.convertStringToObject(value, colMd);
assertEqualData(expValue.getSecond(), valueObj);
}
}
}
示例6: getFormatString
import org.apache.commons.lang.time.FastDateFormat; //导入方法依赖的package包/类
private static String getFormatString(Date date, FastDateFormat format){
String formatString = format.format(date);
return extractDateTime(formatString);
}
示例7: getParamReplacement
import org.apache.commons.lang.time.FastDateFormat; //导入方法依赖的package包/类
@Override
public String getParamReplacement(Object value, boolean pstmt) {
FastDateFormat fdf = FastDateFormat.getInstance(MysqlNativeConstants.MYSQL_DATE_FORMAT);
return "'" + fdf.format((Date) value) + "'";
}
示例8: format
import org.apache.commons.lang.time.FastDateFormat; //导入方法依赖的package包/类
/**
* Format given date using given format pattern.
*
* @param date the date to format
* @param pattern the pattern to use ({@link SimpleDateFormat})
* @return the resulting string
*/
public static String format(Date date, String pattern) {
FastDateFormat formatter = FastDateFormat.getInstance(pattern);
return formatter.format(date);
}
示例9: getFormattedTimeWithDiff
import org.apache.commons.lang.time.FastDateFormat; //导入方法依赖的package包/类
/**
* Formats time in ms and appends difference (finishTime - startTime)
* as returned by formatTimeDiff().
* If finish time is 0, empty string is returned, if start time is 0
* then difference is not appended to return value.
*
* @param dateFormat date format to use
* @param finishTime finish time
* @param startTime start time
* @return formatted value.
*/
public static String getFormattedTimeWithDiff(FastDateFormat dateFormat,
long finishTime, long startTime) {
String formattedFinishTime = dateFormat.format(finishTime);
return getFormattedTimeWithDiff(formattedFinishTime, finishTime, startTime);
}