本文整理汇总了Java中com.ibm.icu.text.DateFormat.format方法的典型用法代码示例。如果您正苦于以下问题:Java DateFormat.format方法的具体用法?Java DateFormat.format怎么用?Java DateFormat.format使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.ibm.icu.text.DateFormat
的用法示例。
在下文中一共展示了DateFormat.format方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.ibm.icu.text.DateFormat; //导入方法依赖的package包/类
public static void main(String[] args) {
// Oracle JDK
// Locale locale = Locale.forLanguageTag("pt-PT");
// ResourceBundle resource = LocaleData.getDateFormatData(locale);
// String[] shortWeekdays = resource.getStringArray("DayAbbreviations");
// System.out.println(Arrays.asList(shortWeekdays));
// Android + ICU
ULocale loc = new ULocale("pt_PT");
DateFormat df = new SimpleDateFormat("EEE", loc);
String s = df.format(new Date(1494115200L));
System.out.println(s);
}
示例2: getDate
import com.ibm.icu.text.DateFormat; //导入方法依赖的package包/类
/**
* Gets the current date if the given timestamp is empty or null.
*
* @param timestamp the timestamp
* @return the current timestamp if the given one is null.
*/
private String getDate(String timestamp) {
if (timestamp == null || timestamp.isEmpty()) {
DateFormat dateFormat = new SimpleDateFormat(
"EEE, d MMM yyyy HH:mm:ss z");
timestamp = dateFormat.format(new Date());
}
return timestamp;
}
示例3: testCheck_Simple
import com.ibm.icu.text.DateFormat; //导入方法依赖的package包/类
@Test
public void testCheck_Simple() {
// TODO(antkrumin): Rewrite with mocks.
DateFormat dateFormat1 =
DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, ULocale.JAPAN);
DateFormat dateFormat2 =
DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.SHORT, ULocale.JAPAN);
String actualValue = dateFormat1.format(TestUtils.generateRandomDate()) + " :::: "
+ dateFormat2.format(TestUtils.generateRandomDate());
Placeholder testToken =
Placeholder.builder("date", actualValue).putSplitterParam("::::").build();
checker.check(testToken, ULocale.JAPAN, null);
}
示例4: testCheck_Short
import com.ibm.icu.text.DateFormat; //导入方法依赖的package包/类
@Test
public void testCheck_Short() {
DateFormat dateFormat1 =
DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, ULocale.US);
DateFormat dateFormat2 =
DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, ULocale.US);
String actualValue = dateFormat1.format(TestUtils.generateRandomDate()) + " - "
+ dateFormat2.format(TestUtils.generateRandomDate());
Placeholder testToken = Placeholder.builder("date", actualValue).build();
checker.check(testToken, ULocale.US, null);
}
示例5: testCheck_WordSplitter
import com.ibm.icu.text.DateFormat; //导入方法依赖的package包/类
@Test
public void testCheck_WordSplitter() {
DateFormat dateFormat1 =
DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, new ULocale("ml"));
DateFormat dateFormat2 =
DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, new ULocale("ml"));
String actualValue = dateFormat1.format(TestUtils.generateRandomDate()) + " till "
+ dateFormat2.format(TestUtils.generateRandomDate());
Placeholder testToken =
Placeholder.builder("date", actualValue).putSplitterParam("till").build();
checker.check(testToken, new ULocale("ml"), null);
}
示例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 );
}
示例7: formatCalDateTime
import com.ibm.icu.text.DateFormat; //导入方法依赖的package包/类
public String formatCalDateTime(final Calendar cal, final int timeFormat) {
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, transTimeFormat(timeFormat), iLocale);
df.setCalendar(cal);
return df.format(cal.getTime());
}
示例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());
}
示例9: formatCalTimeOnly
import com.ibm.icu.text.DateFormat; //导入方法依赖的package包/类
public String formatCalTimeOnly(final Calendar cal, final int timeFormat) {
DateFormat df = DateFormat.getTimeInstance(transTimeFormat(timeFormat), iLocale);
df.setCalendar(cal);
return df.format(cal.getTime());
}
示例10: getDateOnly
import com.ibm.icu.text.DateFormat; //导入方法依赖的package包/类
/**
* Gets the date only.
*
* @param date
* the date
* @return the date only
*/
public String getDateOnly(final Date date) {
DateFormat df = getDateOnlyFormat();
synchronized (df) {
return df.format(date);
}
}
示例11: getTimeOnly
import com.ibm.icu.text.DateFormat; //导入方法依赖的package包/类
/**
* Gets the time only.
*
* @param date
* the date
* @return the time only
*/
public String getTimeOnly(final Date date) {
DateFormat df = getTimeOnlyFormat();
synchronized (df) {
return df.format(date);
}
}
示例12: getDateTime
import com.ibm.icu.text.DateFormat; //导入方法依赖的package包/类
/**
* Gets the date time.
*
* @param date
* the date
* @return the date time
*/
public String getDateTime(final Date date) {
DateFormat df = getDateTimeFormat();
synchronized (df) {
return df.format(date);
}
}