当前位置: 首页>>代码示例>>Java>>正文


Java FastDateFormat.format方法代码示例

本文整理汇总了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 "";
    }
}
 
开发者ID:JumpMind,项目名称:metl,代码行数:17,代码来源:ModelAttributeScriptHelper.java

示例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);
        }
    }
}
 
开发者ID:wangchongjie,项目名称:olap-access,代码行数:21,代码来源:BaseItem.java

示例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);
}
 
开发者ID:sunlin901203,项目名称:example-java,代码行数:12,代码来源:DateFormatExample.java

示例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);
}
 
开发者ID:Nocket,项目名称:nocket,代码行数:15,代码来源:TouchedListenerModelWrapper.java

示例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);
		}
	}		
}
 
开发者ID:Tesora,项目名称:tesora-dve-pub,代码行数:33,代码来源:DBTypeBasedUtilsTest.java

示例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);
}
 
开发者ID:nortal,项目名称:j-road,代码行数:5,代码来源:Parser.java

示例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) + "'";
}
 
开发者ID:Tesora,项目名称:tesora-dve-pub,代码行数:7,代码来源:DBTypeBasedUtils.java

示例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);
}
 
开发者ID:victorrentea,项目名称:training,代码行数:12,代码来源:DateUtils.java

示例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);
}
 
开发者ID:hopshadoop,项目名称:hops,代码行数:17,代码来源:StringUtils.java


注:本文中的org.apache.commons.lang.time.FastDateFormat.format方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。