Error getting epoch in Date object

2

It's something basic but I'm stuck in this conversion of dates: I receive a date in String with format

  

10/19/2017

and I have to convert them into epoch for this I do:

 Date dataObjUntil = null;
              SimpleDateFormat sdf = new SimpleDateFormat("dd/mm/yyyy");
                        try {
                            dataObjUntil = sdf.parse(untilDate);
                        } catch (ParseException e) {
                            Log.i("error", e.getMessage());
                        }
   long segundos = dataObjUntil.getTime()/1000

but I get

  

1484781000

what is

  

Thursday, January 19, 2017 0:10:00

Can someone tell me what I'm wrong about? , I'm not interested in using libraries type JodaTime since I only have to do this operation

    
asked by JoCuTo 02.11.2017 в 18:36
source

1 answer

1

You have the wrong date format. Use MM for the months instead of mm that represents the minutes:

Date dataObjUntil = null;
Date dataObjUntil = null;
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
try {
    dataObjUntil = sdf.parse(untilDate);
} catch (ParseException e) {
    Log.i("error", e.getMessage());
}
long segundos = dataObjUntil.getTime()/1000

mm in minuscule represents the minutes, while MM in capital letters represents the months of a date:

MM = meses
mm = minutos
    
answered by 02.11.2017 / 19:23
source