• Post Reply Bookmark Topic Watch Topic
  • New Topic

date format question  RSS feed

 
Ranch Hand
Posts: 49
Java Netbeans IDE PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

I have a problem with a date issue. I want to format a value from a SimpleDateFormat
object into a date without a timestamp or a GMT field. The date in question is a custom
one and not a date object from an instance of a Calendar like



I am using the set method in the Calendar class to initialize a date starting from
the first of january, 1900. I have used the clear method in the forementioned class
to clear the timestamp in the calendar object but it doent works at all or maybe i am
totally missing something out here.



I hope someone can point me to a correct solution to my problem in question. I am a beginner so i have to
pardon my poor attempts in this post.

Krillian.

 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you say "doesn't work", what do you mean? You wouldn't expect that line to output anything, because there's no statement to print anything. Did you mean something else? What are you expecting to happen?

(I also assume today should say date, or vice-versa)
 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see that you're using the no-argument method on DateFormat which is probably why you're having trouble getting the correct format.

I don't know if this will help, but a few months ago, I needed to get a Localized time String, note: time not date this is another method of DateFormat. My solution was to cast the DateFormat.getTimeInstance() method to SimpleDateFormat, such as in this code snip-it below:

Note: My test was "safe," only because I used a predefined Locale, but this cast should be in a try-catch block, with a backup format String, because casting DateFormat to SimpleDateFormat can throw an exception in some exotic locals...
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to be clear a Date represents a certain point in time. DateFormat can be used to present that value in a certain way. A Date can't have a certain format. It only has a default one for debugging purposes.
 
krillian konstatos
Ranch Hand
Posts: 49
Java Netbeans IDE PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks to all for the replies on this post. i think i have taken too much water over my head for this problem. I think the solution has more to do with components than date programming. it's just that i have a complex form with a lot of labels spinners, textfields and so on and i want to present default values such as "none applicable" at the start in every component. i think i rather use a checkbox next to the component in question with the label "N/A" when it comes to spinner components and in a combobox i can just have an empty selection value at the top of the list.
//Krillian.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!