Java_Locale纪要(java.util.Locale)

本文详细探讨了Java中的Locale类,它是用于表示特定区域的习惯用法,如语言、国家和变体。内容涵盖了Locale的构造方法、常用方法以及如何在国际化的应用中使用Locale进行日期、数字和字符串的格式化。
摘要由CSDN通过智能技术生成
java.util.Locale

Locale: Locale代表地区;每创建一个Locale对象就会代表一个政治地理位置;

    特点:在Date、Calendar等表示日期时间对象使用中由于不同地理位置及语言的不同会经常用到;

    对象获取方式:
        1. Locale locale = Locale.getDefault();
        2. Locale对象内置了国际常用的静态常量;可以直接获取;
            列举如下:
                public static final Locale CANADA
                public static final Locale CANADA_FRENCH
                public static final Locale CHINA
                public static final Locale CHINESE
                public static final Locale ENGLISH
                public static final Locale FRANCE
                public static final Locale FRENCH
                public static final Locale GERMAN
                public static final Locale GERMANY
                public static final Locale ITALIAN
                public static final Locale ITALY
                public static final Locale JAPAN
                public static final Locale JAPANESE
                public static f
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if (Intent.ACTION_TIME_TICK.equals(action) || Intent.ACTION_TIME_CHANGED.equals(action) || Intent.ACTION_TIMEZONE_CHANGED.equals(action) || Intent.ACTION_LOCALE_CHANGED.equals(action)) { if (Intent.ACTION_LOCALE_CHANGED.equals(action) || Intent.ACTION_TIMEZONE_CHANGED.equals(action)) { // need to get a fresh date format mDateFormat = null; } updateClock(); } } }; public DateView(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_TIME_TICK); filter.addAction(Intent.ACTION_TIME_CHANGED); filter.addAction(Intent.ACTION_TIMEZONE_CHANGED); filter.addAction(Intent.ACTION_LOCALE_CHANGED); mContext.registerReceiver(mIntentReceiver, filter, null, null); updateClock(); } @Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); mDateFormat = null; // reload the locale next time mContext.unregisterReceiver(mIntentReceiver); } protected void updateClock() { if (mDateFormat == null) { final String dateFormat = getContext().getString(R.string.system_ui_date_pattern); final Locale l = Locale.getDefault(); final String fmt = ICU.getBestDateTimePattern(dateFormat, l.toString()); mDateFormat = new SimpleDateFormat(fmt, l); } mCurrentTime.setTime(System.currentTimeMillis()); final String text = mDateFormat.format(mCurrentTime); if (!text.equals(mLastText)) { setText(text); mLastText = text; } } }
最新发布
06-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值