0

I am trying to use to insert a date to my sqlite database.

public CardHolder(String firstName, String lastName, String barcodeNb,
                         Date dateOfBirth,Date expiryDate)

Where I initiated this instance in the mainActivity

 CardHolder person1 =new CardHolder("John","example","123123",new
                    java.sql.Date(1993,9,3),new java.sql.Date(1993,9,3));

But it shows that java.sql.Date is deprecated, what should I use instead?

infinity911
  • 201
  • 1
  • 9
  • 2
    Date isn't deprecated, but the constructor you are using is. I would recommend looking at the javadoc for the class and picking another way of constructing your Date objects – beresfordt Mar 11 '16 at 10:52
  • see here for more info http://stackoverflow.com/questions/887653/jdbc-dates-deprecated-in-java-java-sql-package you find your solution here – Kishan patel Mar 11 '16 at 10:55
  • @beresfordt I want to save the date in a specific format( any known format date) not in Milliseconds – infinity911 Mar 11 '16 at 11:53
  • @RimaHajou `new java.sql.Date(60707833200000L)` produces an object which is equal to `new java.sql.Date(1993,9,3)`; it is just a different method of construction. It is worth noting that `new java.sql.Date(1993,9,3)` does not do what you think it does.. You should read the javadoc – beresfordt Mar 11 '16 at 12:34

1 Answers1

1
new java.sql.Date(new GregorianCalendar(1993, 9, 3).getTimeInMillis())
agad
  • 2,192
  • 1
  • 20
  • 32
  • I want to save it in a date format – infinity911 Mar 11 '16 at 11:51
  • FYI, the troublesome old date-time classes such as `java.util.Date`, `java.util.Calendar`, and `java.text.SimpleDateFormat` are now legacy, supplanted by the [*java.time*](https://docs.oracle.com/javase/10/docs/api/java/time/package-summary.html) classes. Most of the *java.time* functionality is back-ported to Java 6 & Java 7 in the [***ThreeTen-Backport***](http://www.threeten.org/threetenbp/) project. Further adapted for earlier Android (<26) in [***ThreeTenABP***](https://github.com/JakeWharton/ThreeTenABP). See [*How to use ThreeTenABP…*](http://stackoverflow.com/q/38922754/642706). – Basil Bourque Dec 31 '18 at 00:40