The moose likes Java in General and the fly likes Converting Date into Day, Month, Year Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Converting Date into Day, Month, Year" Watch "Converting Date into Day, Month, Year" New topic
Author

Converting Date into Day, Month, Year

Eric Tan
Ranch Hand

Joined: Oct 11, 2006
Posts: 72
I have a text file that shows like this in every row

Testing,Fri 12/15/06,Fri 12/15/06,0 hrs


i will be using a delimiter to tokenized it by the symbol " , ". the problem now is the text files contain the day and date together as one attribute. how can i cut the day off and just read the date and split the dates into month/day/year? so that i can generate the gantt chart using this values?

can anyone help me on this? Thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35249
    
    7
The java.text.SimpleDateFormat class is helpful for this. Something like the following might do the trick (haven't tested this, so there might be problems, but you get the idea):


Android appsImageJ pluginsJava web charts
pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547
- or use another (or the same ?) Tokenizer to split the date string by '/'
- or use java.util.Regexp

pascal
Eric Tan
Ranch Hand

Joined: Oct 11, 2006
Posts: 72
yea. i got what you meant. look through it already. thanks alot for the info. now i have small little problem. as everyone know that i am using Stringtokenizer to read the token to token. the problem i tried how to embed the SimpleDateFormat into StringTokenizer to read it into day, month, year but fail. can anyone guide me on this?


and another update is, the user that pass me the text file successfully grab it without have the day together the date
so the text file will be read in this way

Testing,12/15/06,12/15/06

so this will be the new type of data that i have to read. another issue is, can i use StringTokenizer to start reading only from the 2nd line because the 1st line is just the header of the file??

thanks alot guys. for your help. really appreciate it
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35249
    
    7
I'm not sure what you mean by "embed the SimpleDateFormat into StringTokenizer". The tokenizer works in a loop (typically while { ... } ). In that loop you'd have the code I mentioned before. If you post that section of your code we could take a look at it.

StringTokenizer (or any other way to split up text) will not help with skipping the first line, because it only works on full lines of text. Skipping the first line must be accomplished by the code reading the file. Something like this will do the trick:
Eric Tan
Ranch Hand

Joined: Oct 11, 2006
Posts: 72
this is a workable sample i got the net. i want to ask some help on, how to retrieve just the day or the month from the startDate? for example, 2001-01-01... so if i want to display the day, it's going to print out "01". how can i do that? can anyone guide me one this? i tried on the codes that i just bold on. but still got error


Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35249
    
    7
but still got error

What does this mean - are you getting an exception? If so, tells us which one it is, and in which line it occurs.

Note that the methods of the Date class will not return something like "01", because they only deal with integers, not strings. If you want all days to have two digits, you'll need to add a line of code that prepends the zero if the value is smaller than 10.
[ November 27, 2006: Message edited by: Ulf Dittmer ]
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Converting Date into Day, Month, Year
 
Similar Threads
Finding Dates from Local System
add 10 days to currentDate in java.util.Date or cast to Calendar?
Scanner question
Date help
Object Control Creation – From Constructor?