fecha de análisis siempre volviendo 01 Ene 1970

Sandip Patil Armal:

Me estoy haciendo de fecha y hora del servidor en UTC, así que necesito para convertirla en hora local y la necesidad de almacenar en dB en formato largo.

Pero cada vez que recibo tiempo, analizarlo en "yyyy-MM-dd'T'HH:mm:ss.SSS"y después convertirlo en la que longy lo almacenan en la tabla. pero cuando he intentado a buscar siempre estoy recibiendo 01 Jan 1970.

Aquí está mi código:

Este es el formato en el que estoy recibiendo desde el servidor: "tourCreationDateTime":"2020-03-04T07:12:52.215+0000".

// insert tour details
Tour tour = new Tour();
if (tourId > 0) {
     tour.setId(tourId);
}
tour.setStatus(Constants.TOUR_STATUS_OPEN);
tour.setTourNumber(tourResponseDetails.getTourId());
tour.setCreatedDateTime(DateUtils.getFormattedDate(tourResponseDetails.getTourCreationDateTime(), DateUtils.DATE_FORMAT_DB));
tourDao().insertTour(tour);

Aquí está mi formato de fecha:

public static final String DATE_FORMAT_DB = "yyyy-MM-dd\'T\'HH:mm:ss.SSS";    

Aquí está getFormattedDateel método:

 public static long getFormattedDate(String dateString, String format){
    if(!TextUtils.isEmpty(dateString)){
        return 0L;
    }

    try {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format, Locale.US);
        Date date = simpleDateFormat.parse(dateString);
        return date.getTime();

    } catch (ParseException e) {
        e.printStackTrace();
    }
    return 0L;
}

Ni lo que va mal. Cualquier referencia va a ser muy buena.

Kirguduck:
if(!TextUtils.isEmpty(dateString)){
    return 0L;
} 

y 0L es el 01 Ene 1970.
error aquí - if(!TextUtils.isEmpty(dateString)).
¿está seguro de que debe contener! // signo de exclamación

Supongo que te gusta

Origin http://43.154.161.224:23101/article/api/json?id=282965&siteId=1
Recomendado
Clasificación