Ggdw
Ggdw

Reputation: 2699

java.util.Date class using joda

I want to get a java.util.Date class using joda. I need that the date in Date class will be format as yyyy-MMM-dd HH:mm:ss and GMT/UTC time.

Thanks.

I will clarify my question: i want that when i print toString of Date i will get the time in format of yyyy-MMM-dd HH:mm:ss and as UTC/GMT time.

Upvotes: 0

Views: 201

Answers (2)

Ilya
Ilya

Reputation: 29693

There is method DateTime::toDate() inherited from AbstractInstant

You can format java.util.Date with
SimpleDateFormat

and you can format DateTime with
DateTimeFomratter

Or you can extend Date class

public class MyDate extends Date
{
   private SimpleDateFormat FORMATTER = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss");

   public MyDate(Date date)
   {
      super(date.getTime());
   }

   @Override
   public String toString()
   {
      return FORMATTER.format(this);
   }
}

Upvotes: 0

Evgeni Dimitrov
Evgeni Dimitrov

Reputation: 22506

DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MMM-dd HH:mm:ss");
DateTime jodaDate = fmt.parseDateTime(utilDate);

Upvotes: 1

Related Questions