gpt4 book ai didi

java - 如何将日期时间转换为日期?

转载 作者:行者123 更新时间:2023-11-29 23:25:39 26 4
gpt4 key购买 nike

Cotacoes 类中,我有 creation_date 字段,它是一个日期,但在服务器上它是一个日期时间。收到 JSON 后,出现以下错误:

java.text.ParseException: Failed to parse date ["2018-11-05T12:12:37.307']: No time zone indicator

如何解决这个问题?我使用 retrofit 从服务器调用和接听电话。

cocoa bean :

public class Cotacoes implements Serializable {

private static final long serialVersionUID = 842387749350567455L;
@SerializedName("quotation_id")
@Expose
private int quotation_id;
//private int transaction_id;
@SerializedName("pecas")
@Expose
private List<Pecas> pecas;
@SerializedName("creation_date")
@Expose
private Date creation_date;
// private int duration;
@SerializedName("brand")
@Expose
private String brand;
@SerializedName("vehicle")
@Expose
private String vehicle;

....
getters and setters
}

改造:

public class APIRetrofit {
public static final String BASE_URL = "http://server.net/";
private static Retrofit retrofit = null;

private static Gson gson = new GsonBuilder()
.create();


public static Retrofit getRetrofitClient() {
if (retrofit==null) {
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
}
return retrofit;
}
}

接口(interface):

public interface APIService {

interface ReturnFutureCallback<T> {
void onSuccess(T retorno);

void onFailure(T retorno);
}

@POST("/cotacao")
@FormUrlEncoded
Call<JsonQuotationResponse> listaCotacao(@Header("Authorization") String token, @Field("seller_company_id") String seller_company_id);

}

最佳答案

  • 我认为,在服务器上,它是 longtime 或 String,所以 creation_date 字段,它是 longtime 或 String

关于java - 如何将日期时间转换为日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53611972/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com