本文整理匯總了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);
}