Java Code Examples for com.ibm.icu.text.SimpleDateFormat#toPattern()

The following examples show how to use com.ibm.icu.text.SimpleDateFormat#toPattern() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DateFormatter.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private com.ibm.icu.text.DateFormat hackMilliSecond(
		com.ibm.icu.text.DateFormat factoryFormat )
{
	if ( factoryFormat instanceof SimpleDateFormat )
	{
		SimpleDateFormat factorySimpleFormat = (SimpleDateFormat) factoryFormat;
		String pattern = factorySimpleFormat.toPattern( );

		if ( pattern.indexOf( "SSS" ) == -1 )
		{
			int idx = pattern.indexOf( "ss" );
			if ( idx >= 0 )
			{
				StringBuffer strBuf = new StringBuffer( pattern );

				strBuf.insert( idx + 2, ".SSS" );
				pattern = strBuf.toString( );
			}
		}
		return new SimpleDateFormat( pattern, locale );
	}
	return factoryFormat;
}
 
Example 2
Source File: DateFormatter.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns format code according to format type and current locale
 */
public String getFormatCode( )
{
	if ( UNFORMATTED.equals( formatPattern ) ||
			DATETIME_UNFORMATTED.equals( formatPattern ) ||
			DATE_UNFORMATTED.equals( formatPattern ) ||
			TIME_UNFORMATTED.equals( formatPattern ) )
	{
		return ( (SimpleDateFormat) dateFormat ).toPattern( );
	}
		
	SimpleDateFormat format = getFormatter( );
	if ( format == null )
	{
		return ( (SimpleDateFormat) dateFormat ).toPattern( );
	}
	else
	{
		return format.toPattern( );
	}
}
 
Example 3
Source File: DateFormatter.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private com.ibm.icu.text.DateFormat hackYear(
		com.ibm.icu.text.DateFormat factoryFormat )
{
	// Try cast this to SimpleDateFormat - DateFormat
	// JavaDoc says this should
	// succeed in most cases
	if ( factoryFormat instanceof SimpleDateFormat )
	{
		SimpleDateFormat factorySimpleFormat = (SimpleDateFormat) factoryFormat;

		String pattern = factorySimpleFormat.toPattern( );
		// Search for 'yy', then add a 'y' to make the year 4
		// digits
		if ( pattern.indexOf( "yyyy" ) == -1 )
		{
			int idx = pattern.indexOf( "yy" );
			if ( idx >= 0 )
			{
				StringBuffer strBuf = new StringBuffer( pattern );
				strBuf.insert( idx, 'y' );
				pattern = strBuf.toString( );
			}
		}
		return new SimpleDateFormat( pattern, locale );
	}
	return factoryFormat;
}