• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

UTF date formatting

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am trying to write data to a csv file. It contains a date string.




In the string buffer (cvsBuffer) it is showing the date string in the correct format that I am expecting (mm/dd/YY). But after writing to csv file it is coming in mm/dd/yyyy format. Is it happening due to utf-8 foramtting? If yes please help me how to avoid this date formatting.

Thanks
Manoj
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, I don't think there's any way that UTF-8 would cause that. It seems more likely that there's some other mix-up. Have you looked at the CSV file yourself, or are you relying on some other program which reads the file and parses that field as a Date?
 
Manoj Raghuwanshi
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes I saw the CSV file.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is mysterious. You have ascertained that in the StringBuffer the date is in mm/dd, and after it's run through toString and getBytes, it is in dd/mm? You could check whether it's still correct after the toString operation.
 
Manoj Raghuwanshi
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, after toString its is mm/dd/yy but after getBytes(�utf-8�) it becomes mm/dd/yyyy.
If it is 08/05/07 it becomes 08/05/2007
 
Manoj Raghuwanshi
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, after toString its is mm/dd/yy but after getBytes(�utf-8�) it becomes mm/dd/yyyy.
If it is 08/05/07 it becomes 08/05/2007
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Frankly, what you describe does not seem to be possible. I think there's likely been some mixup either before or after the getBytes() method call. To figure this out, I recommend putting some print statements as close as possible to the call, before and after:

This should give a better picture of where the problem really lies.
 
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 just ran the following, and it confirms that all is well in this part of the code (meaning it prints "true").

Where are you seeing the "2007"? Some programs -like Excel- format CSV data upon import, thereby turning 2-digit years into 4-digit years, so that would not be a valid test.
 
Manoj Raghuwanshi
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes Ulf it is indeed Excel issue. Excel is formatting the date. Thanks Ulf,Jim.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic