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
  • 67,715
  • 15
  • 98
  • 113
David
  • 5
  • 5
  • Do you want to get the `long` as the concatenation of ddMMyyyy, or the number of milliseconds between epoch and the `Date` represented by this `String` ? – Florent Bayle Dec 12 '14 at 12:12
  • I need the date in format long to insert it in Google Calendar intent – David Dec 12 '14 at 13:32
  • So, I think that you need a number of milliseconds from epoch, as given in @Jens answer. – Florent Bayle Dec 12 '14 at 13:40
  • possible duplicate of [Convert Date string with Time to long date](http://stackoverflow.com/questions/17305048/convert-date-string-with-time-to-long-date) – Basil Bourque Dec 14 '14 at 03:56
  • Please search StackOverflow before posting. This topic has been handled in hundreds of Questions and Answers. – Basil Bourque Dec 14 '14 at 03:56

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
  • 67,715
  • 15
  • 98
  • 113
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,198
  • 4
  • 19
  • 24