0

I am converting the Calendar instance result.submissionDate to java.sql.Timestamp as below, am wondering is there any alternative efficient way to do this by avoiding creating new Timestamp object?

invoice.setSubmittedAt(new java.sql.Timestamp(result.submissionDate.getTimeInMillis()));
Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
OTUser
  • 3,788
  • 19
  • 69
  • 127
  • 1
    You want to create a Timestamp without creating a Timestamp? That isn't possible. What is the problem in creating Timestamp objects? Why do you think you should avoid it? – JB Nizet May 15 '19 at 15:52
  • If you are using a Timestamp, I suppose you interact with a DB - the time to create a Timestamp object is completely negligible vs. accessing the DB. – assylias May 15 '19 at 15:53
  • 1
    you can map the column to a Long and get rid of the middle man. but yeah big picture it would be surprising if the timestamp object was an efficiency issue; measure first, don't guess. – Nathan Hughes May 15 '19 at 16:08
  • I recommend you neither use `Calendar` nor `Timestamp`. Those classes are poorly designed and long outdated. Instead depending on circumstances use `OffsetDateTime`, `ZonedDateTime` and/or `Instant`, all from [java.time, the modern Java date and time API](https://docs.oracle.com/javase/tutorial/datetime/). – Ole V.V. May 17 '19 at 12:00

0 Answers0