aspose file tools*
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
Author

date returning null

Joyce Derzaph
Greenhorn

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());
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

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.

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


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.
 
Consider Paul's rocket mass heater.
 
subject: date returning null