【问题标题】:Format date like system format using Time.getCurrentTimezone()使用 Time.getCurrentTimezone() 像系统格式一样格式化日期
【发布时间】:2014-09-22 08:38:11
【问题描述】:

我使用Time.getCurrentTimezone() 来获取当前时区和日期。 我正在获取并格式化它:

private void setDate() {
    Time today = new Time(Time.getCurrentTimezone());
    today.setToNow();

    tvdate2.setText(today.monthDay + "-" + today.month + "-" + today.year);
}

如何根据系统设置格式化日期? 我没能通过 SimpleDateFormat 完成它...

【问题讨论】:

    标签: android date date-format


    【解决方案1】:

    您可以使用 SimpleDateFormat 类以任何格式获取时间。请参考这个 Calendar cal = Calendar.getInstance(); String currentDate = cal.get(Calendar.DAY_OF_MONTH)+"/"+(cal.get(Calendar.MONTH)+1)+"/"+cal.get(Calendar.YEAR); Date date = new SimpleDateFormat("dd/MM/yyyy HH:mm", Locale.ENGLISH).parse(currentDate);

    【讨论】:

    • 谢谢,但我实际上不想使用Calendar。使用我的方法有什么建议吗?
    猜你喜欢
    • 1970-01-01
    • 2021-08-01
    • 1970-01-01
    • 2018-12-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-30
    • 1970-01-01
    • 2021-01-22
    相关资源
    最近更新 更多