【问题标题】:Add current Date to Time UTC String and Convert to Device Time添加当前日期到时间 UTC 字符串并转换为设备时间
【发布时间】:2019-10-14 06:38:34
【问题描述】:

我有一个 UTC 时间字符串(05:30:00) 将当前日期添加到字符串中并将 (UTC DateTime) 转换为 (设备时间)

注意:不使用 ZoneID

【问题讨论】:

    标签: android date time


    【解决方案1】:
    String dateStr = "Jul 16, 2013 12:08:59 AM";
    SimpleDateFormat df = new SimpleDateFormat("MMM dd, yyyy HH:mm:ss a", Locale.ENGLISH);
    df.setTimeZone(TimeZone.getTimeZone("UTC"));
    Date date = df.parse(dateStr);
    df.setTimeZone(TimeZone.getDefault());
    String formattedDate = df.format(date);
    

    注意:不要忘记包含“a”(上午/下午标记)而不是“z”(时区)。

    【讨论】:

    • 首先将完整的日期和时间字符串转换为UTC我需要将当前日期添加到给定的时间字符串。
    猜你喜欢
    • 2018-08-21
    • 2015-10-24
    • 2014-02-22
    • 2011-06-13
    • 2012-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-18
    相关资源
    最近更新 更多