【问题标题】:How to send ISO format date from android to backend?如何将 ISO 格式日期从 android 发送到后端?
【发布时间】:2016-08-30 12:11:36
【问题描述】:

我正在构建一个使用日期和时间的应用程序。我必须以 ISO 格式发送时间和时间。我目前正在发送这样的时间:

 calendar = Calendar.getInstance();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
        simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
        String time = simpleDateFormat.format(calendar.getTime());

发送ISO格式的时间我应该改变什么?

编辑:这是我后端的错误:

Invalid format: "2016-08-30T13:54:22Z" is malformed at "Z"

【问题讨论】:

  • 你用什么将日期发送到后端?
  • 举个例子ISO format of time
  • 你的格式对我来说很好,有什么我遗漏的问题吗?
  • @himanshu1496 问题是我的后端无法解析我发送的这种类型的时间......

标签: android android-date


【解决方案1】:

我正在使用date-format-iso8601 库。很有帮助。

用法:

DateFormat f = new Iso8601ExtendedOffsetDateTimeFormat();
String date = f.format(System.currentTimeMillis());
long dateMillis = f.parse("date-string").getTime();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-13
    相关资源
    最近更新 更多