【问题标题】:Date conversion of the format containing "e" in the milliseconds以毫秒为单位的包含“e”的格式的日期转换
【发布时间】:2019-01-10 01:27:31
【问题描述】:

“1.5332445E9”如何转换为日期和时间?

到现在我都试过了

private String getDate(long time) {
            Date date = new Date(time);
            return Utils.getFormattedDate(date, "dd/MM/yyyy HH:mm:ss a");
        }
public static String getFormattedDate(Date date, String desiredFormat) {
                DateFormat dateFormat = new SimpleDateFormat(desiredFormat);
                dateFormat.format(date);
                return dateFormat.format(date);
            }

任何帮助将不胜感激。

【问题讨论】:

标签: android android-studio datetime simpledateformat date-format


【解决方案1】:

你不能。你必须使用长值而不是这个格式化的字符串

【讨论】:

    【解决方案2】:

    如果此字符串表示毫秒,则获取日期如下:

    String s = "1.5332445E9";
    Double doubleMils = 0.0;
    try {
        doubleMils = Double.parseDouble(s);
    } catch (NumberFormatException e) {
        e.printStackTrace();
    }
    Long longMils = doubleMils.longValue();
    
    Date date = new Date(longMils);
    

    现在您可以随意格式化date

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-19
      • 2022-11-27
      • 1970-01-01
      • 2017-10-02
      • 2012-12-12
      • 1970-01-01
      相关资源
      最近更新 更多