Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Changing the date format

 
Davy Kelly
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey everyone,

I have a method that gets todays date, but I can't get it to change the format. right now it is Friday 4 May 2007 but I want it to display like Friday 04 May 2007.
here is my code:


I tried the SimpleDateFormat but I can't seem to get it to work, any ideas?

davy
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
SimpleDateFormat is the way to go. Show us what you tried and what you mean by 'it didn't work'. Could you not get it to compile or did it not give you the output you expected ?
 
Davy Kelly
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


i tried:


it compiles but I get a runtime error:


davy
[ May 04, 2007: Message edited by: Davy Kelly ]
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's nothing obvious in that code that would produce a NPE. Which is line 108 ?
 
Davy Kelly
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
today = sdfbs.format(caltoday.getTime()); //line 108

davy
[ May 04, 2007: Message edited by: Davy Kelly ]
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Davy Kelly:
today = sdfbs.format(caltoday.getTime()); //line 108


For that line to throw an NPE, either sdfbs or caltoday must be null. Try putting in some print statements or running it thru a debugger to see which it is.
 
Davy Kelly
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Joanne,

I changed my method, which now works. I had the SimpleDateFormat as a class variable (this was null), so I put it into the method. here it is in full which works.


davy
[ May 04, 2007: Message edited by: Davy Kelly ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic