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?

4
  • 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 Commented Mar 11, 2016 at 10:52
  • see here for more info stackoverflow.com/questions/887653/… you find your solution here Commented Mar 11, 2016 at 10:55
  • @beresfordt I want to save the date in a specific format( any known format date) not in Milliseconds Commented Mar 11, 2016 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 Commented Mar 11, 2016 at 12:34

1 Answer 1

1
new java.sql.Date(new GregorianCalendar(1993, 9, 3).getTimeInMillis())
Sign up to request clarification or add additional context in comments.

2 Comments

I want to save it in a date format
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 classes. Most of the java.time functionality is back-ported to Java 6 & Java 7 in the ThreeTen-Backport project. Further adapted for earlier Android (<26) in ThreeTenABP. See How to use ThreeTenABP….

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.