Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

date returning null

 
Joyce Derzaph
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure if this belongs in this forum or another but the problem is in a servlet.
I'm trying to set a date and it keeps comming up null

currentDate = new Date();
dateSyntax = new SimpleDateFormat("s",Locale.getDefault());
dateSyntax.applyPattern("yyyy-MM-dd");
now = (long)System.currentTimeMillis();
currentDate.setTime(now);
clock = dateSyntax.format(currentDate);

currentDate.setTime(now) is where the problem is. now has a value.

Joyce
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

would be an easier way to get the current time.
[ July 22, 2004: Message edited by: Paul Sturrock ]
 
Shailesh Kini
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try using

public void setLenient(boolean lenient)Specify whether or not date/time parsing is to be lenient. With lenient parsing, the parser may use heuristics to interpret inputs that do not precisely match this object's format. With strict parsing, inputs must match this object's format.

Parameters:
lenient - when true, parsing is lenient
See Also:
Calendar.setLenient(boolean)

parse will throw a null pointer exception if the format is a mismatch.

cheers
skini
 
Ken Robinson
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this:




If you look in the javadoc for java.util.Date, it's constructor description states that a Date created with the new keyword defaults to the current date/time.

The constructor you are using allows you to define the format and Locale in one line without need for a second call to applyPattern.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic