0

I have a String date = dd/MM/yyyy. How can I parse it to long? Have I to get the day, parse to long, get the month, parse to long, get the year, parse to long and then concatenate?

Thanks,

Jens
  • 63,364
  • 15
  • 92
  • 104
David
  • 5
  • 5

2 Answers2

3

Use the Formatter to parse the date:

DateFormat df = new SimpleDateFormat("dd/MM/yyy");
Long date = df.parse("12/12/2014").getTime();
Jens
  • 63,364
  • 15
  • 92
  • 104
0

using simpledateformat you can easily achieve this

public class test {
public static void main(String[] args) {

     String currentDate = "01-March-2016";
     SimpleDateFormat f = new SimpleDateFormat("dd-MMM-yyyy");
     Date parseDate = f.parse(currentDate);
     long milliseconds = parseDate.getTime();
}
}

for More information click Here

Ankit jain
  • 4,048
  • 3
  • 18
  • 24