1

When trying to get a string for the current date using

DateFormat.getDateInstance().format(calendar.getTime())

it keeps returning the wrong day. For example, it is saying today, July 25th., is July 26th. Also when I use it to sat a date picker, I get the day value by using

dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);

When the date picker is set, it also shows the day ahead by 1.

To get the calendar I'm using

Calendar calendar = Calendar.getInstance();

Is there something I'm missing? Thanks

Matt
  • 2,650
  • 4
  • 36
  • 46

1 Answers1

0

I would imagine this is because you havent set the timezone to your timezone, and rather than the day being off randomly, the time zone you are in is diferent than GMT (Greenwich Median? Time). Try looking at this example How to handle calendar TimeZones using Java?

Community
  • 1
  • 1
Adam Storm
  • 724
  • 1
  • 6
  • 13
  • I think you're right... It's showing the same date now that it's 01:22 pacific. I've also changed the code to use Calendar.GetInstance(TimeZone.GetCurrent()) – Matt Jul 26 '11 at 08:25