File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes java.util.Calendar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of RabbitMQ in Depth this week in the Open Source forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "java.util.Calendar" Watch "java.util.Calendar" New topic


JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
I got an error message saying:
Cannot assign value of type 'java.lang.String' to property 'last_logon_date' of type 'java.util.Calendar'
What value I should give that is of type 'java.util.Calendar'?
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
See the doc for the set( field, value) method. You can set individual year, month, day, hour, minute, second fields. A major pain.
If you have a string date in a known format, you can use the DateFormat class to parse it and create a Date, then setTime on the Calendar. I find the date handling in Java very icky (set TIME indeed!) and always code this stuff with the JDK doc open.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
I did not explain my problem better. Sorry.
I have a form for users to fill out the text field. I specify the field as of java.util.Calendar type.
During testing, I filled out the text field with a date in various ways (for example, 06/27/2003, June 27, 2003, etc.) The computer always gave an error message saying the information I had given was of String type.
Therefore, I am wondering what value is of java.util.Calendar type.
Joel McNary

Joined: Aug 20, 2001
Posts: 1824

You have to convert your String to a java.util.Calendar.

Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
Thanks a lot for advices.
I agree. Here's the link:
subject: java.util.Calendar