How to convert TIMESTAMP/DATETIME to Gregoriancalendar?

Asked

Viewed 317 times

1

How do I convert a TIMESTAMP or DATETIME mysql in a GregorianCalendar Java? Or a better idea?

In class, the field dataCadastro is the type GregorianCalendar. I’m recording in the bank on the guy TIMESTAMPdd-MM-yyyy 00:00:00.

Now I want to do the opposite, take from the bank and generate the GregorianCalendar to compose the object.

The idea is to keep the complete data of the user’s registration date!

How to do?

1 answer

1

Timestamp ts = seuTimeStamp;
GregorianCalendar c = new GregorianCalendar();
c.setTime(ts);

or, if it is Date

Date d = seuDate;
GregorianCalendar c = new GregorianCalendar();
c.setTime(d);
  • Gregoriancalendar. No Calendar! ?

  • 1

    in the same way... only instead of using getInstance.. you make a new Gregoriancalendar( )

Browser other questions tagged

You are not signed in. Login or sign up in order to post.