File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes date returning null Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "date returning null" Watch "date returning null" New topic

date returning null

Joyce Derzaph

Joined: Mar 18, 2004
Posts: 14
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());
now = (long)System.currentTimeMillis();
clock = dateSyntax.format(currentDate);

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

Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

would be an easier way to get the current time.
[ July 22, 2004: Message edited by: Paul Sturrock ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Shailesh Kini
Ranch Hand

Joined: Oct 17, 2001
Posts: 153
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.

lenient - when true, parsing is lenient
See Also:

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


Shailesh Kini.
Ken Robinson
Ranch Hand

Joined: Dec 23, 2003
Posts: 101
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.
I agree. Here's the link:
subject: date returning null
It's not a secret anymore!