Android:如何获取默认的日期/时间格式? [英] Android: How to get default date/time format?

查看:252
本文介绍了Android:如何获取默认的日期/时间格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每个时区都有自己的日期/时间格式。
例如,

Each timezone has it's own date/time formats. Say for e.g.,

UK >> dd/MM/yyyy    
US >> M/d/yyyy     

了解更多, https://gist.github.com/mlconnor/1887156

我确定Android可能会找到一种方法默认日期格式。
可以指导任何一种最简单的获取方式吗?

I'm sure Android might've a way to retrive the default date format. Can any guide what would be the simplest way to fetch?

推荐答案

从上面的输入中可以改善答案

from the above input, improved the answer in kotlin with backward compatibility.

 private fun getDefaultDatePattern(): String {

    return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        DateTimeFormatterBuilder.getLocalizedDateTimePattern(
            FormatStyle.SHORT,
            null,
            IsoChronology.INSTANCE,
            Locale.getDefault()
        )
    } else {
        SimpleDateFormat().toPattern()
    }
}

这篇关于Android:如何获取默认的日期/时间格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆