Reputation: 7182
I collect Date from my Spring MVC/ Hibernate app using the following code:
String startMembershipDate = request.getParameter("startmembershipdate");
and I am using the following field definition for this field in my entity
@Column(name="MEMBERSHIP_DATE", nullable=false, unique=false)
private Date membershipDate;
So I was wondering if someone can please provide me with an example on how to convert the received date in the JSP to GMT format using Joda-time?
Also shall I change the field definition from Date to DateTime? Timestamp?
Upvotes: 0
Views: 999
Reputation: 328724
See this question how to convert between Date
and DateTime
: Convert from java.util.date to JodaTime
This question tells you how to get format the DateTime
using GMT: JodaTime DateTime, ISO8601 GMT date format
You can change the field definition to DateTime
if you need to. You just have to write a custom Hibernate mapper then. We do that here and it works well (especially since we save dates as DECIMAL(16)
so we don't get stupid bugs because of odd SQL DATE
implementations, driver bugs, ...).
java.sql.Timestamp
is something else. It's derived from java.util.Date
and only adds the notion of nano seconds - which introduces some new subtleties that you need to be aware of. In my code, I stay away from it.
But unless you have a good reason (like finding that you convert to DateTime
all the time), leave it alone.
Upvotes: 2