I am using Joda 2.5
Facing an issue while converting the Joda LocalDate to LocalDateTime.
As,I am able to convert LocalDate to DateTime with Time atStartOfDay. I wanted the same feature but via LocalDateTime object.
My code is :
Suppose Date is coming from different REST service , say
Date currentDate = new Date("2015-02-05");
And now this Date is passed to some another service as shown below :
funService(currentDate);
public funService(Date currentDate)
{
LocalDate localDateObject = new LocalDate(date);
// Now I have to convert this Date to LocalDateTime
LocalDateTime localDateTime = localDateObject.toDateTimeAtStartOfDay();
//But this returns DateTime Object.
// As I don't want to store the DateTime Object because it also stores the TimeZone
}
I want the LocalDateTime Object as I am storing this LocalDateTime as Timestamp in the mysql.
Please provide the solution for to convert in LocalDate to LocalDateTime Object.
Eg : '2015-02-01' to '2015-02-01 00:00:01' YYYY-MM-DD to YYYY-MM-DD HH:MM:SS:zzz
But not LocalDate to DateTime
Well once you get rid of time zone anomalies, you can probably just assume that every day starts at midnight, so use:
LocalDateTime localDateTime = localDate.toLocalDateTime(LocalTime.MIDNIGHT);
It's not clear why you wanted to end up at 1 second past midnight. If you really want that, create your own constant LocalTime
representing that, and use it instead of MIDNIGHT
in the above code.
Also note that if you've actually got a Date
, you may already have lost information. It sounds like the incoming data is really a string - you'd be best off parsing that directly as a LocalDate
to avoid time zones potentially causing problems.
See more on this question at Stackoverflow