-2

At the moment I have a String with the folowing format :

'DD/MM/YYYY' , and I'm willing to store this in a SQLite database as a date.

Since it is impossible to store it as a datetime, I've decided Integers would be the best choice, and someone told me about the Unix epoch solution. The thing is that I'm very unfamiliar with that, and I can't seem to convert a String into a unix epoch time...

Is there a way to directly convert a String with my format into a unix epoch time, or am I doing it wrong and should I change something?

I've read this question :Unix epoch time to Java Date object But still can not find my way out with my String...

Community
  • 1
  • 1
JohnnyBgud
  • 107
  • 4

2 Answers2

1

Take a look at Parsing String date to date and adjust the format to yours.

If you have a java.util.Date just use http://docs.oracle.com/javase/6/docs/api/java/util/Date.html#getTime() to get the UNIX timestamp as long.

adrobisch
  • 316
  • 1
  • 3
  • Oh I just have to do a double conversion then, why didn't I think of that before... Sorry for the inconvenience, thanks for the doc, I'll use it! – JohnnyBgud May 27 '16 at 07:00
0

If in doubt, read the docs! ;)

https://developer.android.com/reference/java/text/SimpleDateFormat.html

SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
sdf.parse(<value>);
Jeff Sutton
  • 901
  • 7
  • 6