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


Java DateFormat.getDateInstance方法代码示例

本文整理汇总了Java中com.ibm.icu.text.DateFormat.getDateInstance方法的典型用法代码示例。如果您正苦于以下问题:Java DateFormat.getDateInstance方法的具体用法?Java DateFormat.getDateInstance怎么用?Java DateFormat.getDateInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.ibm.icu.text.DateFormat的用法示例。


在下文中一共展示了DateFormat.getDateInstance方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: guessDateFormat

import com.ibm.icu.text.DateFormat; //导入方法依赖的package包/类
/**
 * This function can be overridden by subclasses to use different heuristics.
 * <b>It MUST return a 'safe' value,
 * one whose modification will not affect this object.</b>
 *
 * @param dateStyle
 * @param timeStyle
 * @draft ICU 3.6
 * @provisional This API might change or be removed in a future release.
 */
protected DateFormat guessDateFormat(int dateStyle, int timeStyle) {
    DateFormat result;
    ULocale dfLocale = getAvailableLocale(TYPE_DATEFORMAT);
    if (dfLocale == null) {
        dfLocale = ULocale.ROOT;
    }
    if (timeStyle == DF_NONE) {
        result = DateFormat.getDateInstance(getCalendar(), dateStyle, dfLocale);
    } else if (dateStyle == DF_NONE) {
        result = DateFormat.getTimeInstance(getCalendar(), timeStyle, dfLocale);
    } else {
        result = DateFormat.getDateTimeInstance(getCalendar(), dateStyle, timeStyle, dfLocale);
    }
    return result;
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:26,代码来源:GlobalizationPreferences.java

示例2: get

import com.ibm.icu.text.DateFormat; //导入方法依赖的package包/类
@Override
public ImmutableList<DateFormat> get(Placeholder target, ULocale locale) {
  ImmutableList.Builder<DateFormat> result = ImmutableList.builder();
  for (Integer type : FORMATS) {
    DateFormat dateFormat = DateFormat.getDateInstance(type, locale);
    dateFormat.setLenient(target.isLenient());
    result.add(dateFormat);
  }
  return result.build();
}
 
开发者ID:googlei18n,项目名称:i18n_sanitycheck,代码行数:11,代码来源:DateStringFormatProducer.java

示例3: getPreferredDateFormat

import com.ibm.icu.text.DateFormat; //导入方法依赖的package包/类
/**
 * Returns a preferred format specifier for tick labels that represent axis
 * values that will be computed based on the difference between cdt1 and
 * cdt2
 * 
 * @param iUnit
 *            The unit for which a preferred pattern is being requested
 * @param locale
 *            The locale for format style
 * @param keepHierarchy
 *            indicates if the format should keep hierarchy
 * 
 * @return A preferred datetime format for the given unit
 */
public static final IDateFormatWrapper getPreferredDateFormat( int iUnit,
		ULocale locale, boolean keepHierarchy )
{
	IDateFormatWrapper df = null;
	String pattern = ChartUtil.createDefaultFormatPattern( iUnit,
			keepHierarchy );
	df = new CommonDateFormatWrapper( new SimpleDateFormat( pattern, locale ) );
	// Special cases for dynamic patterns
	switch ( iUnit )
	{
		case Calendar.MONTH :
			if ( keepHierarchy )
			{
				df = new MonthDateFormat( locale );
			}
			break;
		case Calendar.DAY_OF_MONTH :// Same as DATE
			if ( keepHierarchy )
			{
				df = new CommonDateFormatWrapper( DateFormat.getDateInstance( DateFormat.MEDIUM,
						locale ) );
			}
			break;
	}
	return df;
}
 
开发者ID:eclipse,项目名称:birt,代码行数:41,代码来源:DateFormatWrapperFactory.java

示例4: toLocalizedPattern

import com.ibm.icu.text.DateFormat; //导入方法依赖的package包/类
public String toLocalizedPattern( )
{
	DateFormat df = DateFormat.getDateInstance( DateFormat.LONG, locale );
	if ( df instanceof SimpleDateFormat )
	{
		return ( (SimpleDateFormat) df ).toLocalizedPattern( )
				+ "\n"  //$NON-NLS-1$
				+ new SimpleDateFormat( "HH:mm", locale ).toLocalizedPattern( ); //$NON-NLS-1$
	}
	return "MMMM d, yyyy HH:mm";  //$NON-NLS-1$
}
 
开发者ID:eclipse,项目名称:birt,代码行数:12,代码来源:DateFormatWrapperFactory.java

示例5: validateInputString

import com.ibm.icu.text.DateFormat; //导入方法依赖的package包/类
/**
 * Validates the locale-dependent value for the date time type, validate the
 * <code>value</code> in the locale-dependent way and convert the
 * <code>value</code> into a Date object.
 * 
 * @return object of type Date or null if <code>value</code> is null.
 */

public Object validateInputString( Module module, DesignElement element,
		PropertyDefn defn, String value ) throws PropertyValueException
{
	if ( StringUtil.isBlank( value ) )
	{
		return null;
	}

	// Parse the input in locale-dependent way.
	ULocale locale = module == null ? ThreadResources.getLocale( ) : module
			.getLocale( );
	DateFormat formatter = DateFormat.getDateInstance( DateFormat.SHORT,
			locale );
	try
	{
		return formatter.parse( value );
	}
	catch ( ParseException e )
	{
		logger.log( Level.SEVERE, "Invalid date value:" + value ); //$NON-NLS-1$
		throw new PropertyValueException( value,
				PropertyValueException.DESIGN_EXCEPTION_INVALID_VALUE,
				DATE_TIME_TYPE );
	}
}
 
开发者ID:eclipse,项目名称:birt,代码行数:34,代码来源:DateTimePropertyType.java

示例6: format

import com.ibm.icu.text.DateFormat; //导入方法依赖的package包/类
public String format( Date date )
{
	StringBuffer str = new StringBuffer( );
	FieldPosition pos = new FieldPosition( DateFormat.DATE_FIELD );
	DateFormat df = DateFormat.getDateInstance( DateFormat.MEDIUM, locale );
	if ( tz != null )
	{
		df.setTimeZone( tz );
	}
	df.format( date, str, pos );
	int endIndex;
	if ( pos.getEndIndex( ) >= str.length( ) )
	{
		endIndex = pos.getEndIndex( );
	}
	else
	{
		endIndex = pos.getEndIndex( )
				+ ( str.charAt( pos.getEndIndex( ) ) == ',' ? 2 : 1 );
	}
	if ( endIndex >= str.length( ) ) // means date is the last one, need
										// to remove separator
	{
		endIndex = pos.getBeginIndex( );
		while ( endIndex > 0 )
		{
			char ch = str.charAt( endIndex - 1 );
			if ( ch == ' '
					|| ch == ',' || ch == '/' || ch == '-' || ch == '.' )
			{
				endIndex--;
			}
			else
			{
				break;
			}
		}
		return str.substring( 0, endIndex );
	}
	return str.substring( 0, pos.getBeginIndex( ) )
			+ str.substring( endIndex );
}
 
开发者ID:eclipse,项目名称:birt,代码行数:43,代码来源:DateFormatWrapperFactory.java

示例7: testResultIteratorFindGroup3

import com.ibm.icu.text.DateFormat; //导入方法依赖的package包/类
/**
 * 
 */
@Test
   public void testResultIteratorFindGroup3( ) throws Exception
{
	String[] bindingNameGroup = new String[]{
			"GROUP_SALE_DATE", "GROUP_AMOUNT"
	};
	IBaseExpression[] bindingExprGroup = new IBaseExpression[]{
			new ScriptExpression( "dataSetRow[\"SALE_DATE\"]" ),
			new ScriptExpression( "dataSetRow.AMOUNT" )
	};
	GroupDefinition[] groupDefn = new GroupDefinition[]{
			new GroupDefinition( "group1" ), new GroupDefinition( "group2" )
	};
	groupDefn[0].setKeyExpression( "row.GROUP_SALE_DATE" );
	groupDefn[1].setKeyExpression( "row.GROUP_AMOUNT" );

	String[] bindingNameRow = new String[]{
			"ROW_COUNTRY",
			"ROW_CITY",
			"ROW_SALE_DATE",
			"ROW_AMOUNT"
	};
	IBaseExpression[] bindingExprRow = new IBaseExpression[]{
			new ScriptExpression( "dataSetRow[\"COUNTRY\"]", 0 ),
			new ScriptExpression( "dataSetRow.CITY", 0 ),
			new ScriptExpression( "dataSetRow.SALE_DATE", 0 ),
			new ScriptExpression( "dataSetRow.AMOUNT", 0 )
	};
			
	QueryDefinition queryDefn = this.createQuery( bindingNameGroup,
			bindingExprGroup,
			groupDefn,
			null,
			null,
			null,
			null,
			null,
			null,
			bindingNameRow,
			bindingExprRow );
	
	IResultIterator it = executeQuery( queryDefn );
	it.next( );

	DateFormat df = DateFormat.getDateInstance( DateFormat.SHORT, Locale.US );
	testFindGroup( it, new Object[]{
		df.format( df.parse( "05/01/2004" ) )
	}, 5 );
	testFindGroup( it, new Object[]{
			df.format( df.parse( "06/01/2004" ) ), "100"
	}, 3 );
	testFindGroup( it, new Object[]{
			df.format( df.parse( "06/01/2004" ) ), new Integer( 100 )
	}, 3 );
	testFindGroup( it, new Object[]{
			df.format( df.parse( "06/05/2004" ) ), "400"
	}, 1 );

	try
	{
		testFindGroup( it, new Object[]{
				"CHINA", "abc"
		}, 6 );
		fail( "Should convert fails" );
	}
	catch ( BirtException e )
	{
		System.out.println( e.getLocalizedMessage( ) );
	}
}
 
开发者ID:eclipse,项目名称:birt,代码行数:74,代码来源:FeaturesTest.java

示例8: formatCalDateOnly

import com.ibm.icu.text.DateFormat; //导入方法依赖的package包/类
public String formatCalDateOnly(final Calendar cal) {
	DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM, iLocale);
	df.setCalendar(cal);
	return df.format(cal.getTime());
}
 
开发者ID:OpenNTF,项目名称:org.openntf.domino,代码行数:6,代码来源:FormatterImpl.java


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