安卓日期i18n方法

2018-05-18  本文已影响0人  奇松_ca45

Date now = new Date();

        TextView chineseTime = (TextView)findViewById(R.id.chineseShortDate);

        TextView chineseTimeMedium = (TextView)findViewById(R.id.chineseMediumDate);

        TextView preciseTextChinese = (TextView)findViewById(R.id.preciseDateChinese);

        DateFormat chineseDateShort = DateFormat.getDateInstance(DateFormat.SHORT, Locale.CHINESE);

        DateFormat chineseDateMedium = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.CHINESE);

        SimpleDateFormat preciseChineseFormat = new SimpleDateFormat("MMMM yyyy", Locale.CHINESE);

        chineseTime.setText("Chinese default short:"+chineseDateShort.format(now));

        chineseTimeMedium.setText("Chinese default medium:"+chineseDateMedium.format(now));

        preciseTextChinese.setText("Chinese MMMM yyyy:"+preciseChineseFormat.format(now));

        DateFormat englishDateShort = DateFormat.getDateInstance(DateFormat.SHORT, Locale.ENGLISH);

        DateFormat englishDateMedium = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.ENGLISH);

        SimpleDateFormat preciseEnglishFormat = new SimpleDateFormat("MMMM yyyy", Locale.ENGLISH);

        TextView englishDateShortText = (TextView)findViewById(R.id.englishShortDate);

        TextView englishDateMediumText = (TextView)findViewById(R.id.englishMediumDate);

        TextView preciseTextEnglish = (TextView)findViewById(R.id.preciseDateEnlish);

        englishDateShortText.setText("English default short:"+englishDateShort.format(now));

        englishDateMediumText.setText("English default medium:"+englishDateMedium.format(now));

        preciseTextEnglish.setText("English MMMM yyyy:"+preciseEnglishFormat.format(now));

    android:layout_width="match_parent"

    android:orientation="vertical"

    android:layout_height="wrap_content">

        android:id="@+id/chineseShortDate"

        android:layout_width="wrap_content"

        android:text="Chinese time"

        android:layout_height="wrap_content" />

        android:id="@+id/chineseMediumDate"

        android:layout_width="wrap_content"

        android:text="Chinese time"

        android:layout_height="wrap_content" />

        android:id="@+id/preciseDateChinese"

        android:layout_width="wrap_content"

        android:text="presize Date"

        android:layout_height="wrap_content" />

        android:id="@+id/englishShortDate"

        android:layout_width="wrap_content"

        android:text="Englsih time"

        android:layout_height="wrap_content" />

        android:id="@+id/englishMediumDate"

        android:layout_width="wrap_content"

        android:text="Englsih time"

        android:layout_height="wrap_content" />

        android:id="@+id/preciseDateEnlish"

        android:layout_width="wrap_content"

        android:text="presize Date"

        android:layout_height="wrap_content" />

上一篇下一篇

猜你喜欢

热点阅读