• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Converting Date into Day, Month, Year

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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):
 
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
- or use another (or the same ?) Tokenizer to split the date string by '/'
- or use java.util.Regexp

pascal
 
Eric Tan
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 got this tall by not having enough crisco in my diet as a kid. This ad looks like it had plenty of shortening:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic