I am trying to convert java.util.Date into string as “Twenty Sixth of October Nineteen Ninety Three” for the date 26-10-1993.
How to do this in a generic fashion?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You need to extract the 3 parts of the date (the day, the month, the year), and just convert each respectively.
For the day, you’re going to need a number to words converter. You can get a rather general one, or alternatively, since your numeric range is limited, you can write a simpler one that only works for the day range.
For the month, just map it to the month name. This should be straightforward.
For the year, you’re going to have to be more specific on what the requirement is. Is
2010“twenty ten”? What about2009? In any case, fory=19xx,18xx, etc, you can converty % 100andy / 100to words and concatenate them.This is because when
y=1234,y / 100 = 12andy % 100 = 34. The/is the integer division in this context, and%is the remainder operator. Make sure to handle all the special cases, e.g. wheny % 100 == 0, e.g.1800should beeighteen hundred,1907should (perhaps) benineteen o seven, etc.Related questions