Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format a date for use with text-to-speech in Java

I have a Date which I'd like to format into text that is usable by a text-to-speech engine. I am currently doing it by hand using various SimpleDateFormats.

Examples of what should result from formatting:

  • January 25, two thousand one at 6 pm
  • January 25, two thousand at 7 oh 5pm
  • January 25, two thousand eleven at 7 52 pm

Any thoughts? Thanks.

like image 679
Jon Onstott Avatar asked Dec 07 '25 12:12

Jon Onstott


1 Answers

If you are willing to lose precision, there are examples of code that reports the time as "quarter to one" or "five past ten", but the examples I can find all do what you are already doing and use if/then/else to check for all the special cases.

Take a look at http://sourceforge.net/projects/fuzzytime/ for a Python script that does this, or search for "fuzzy time" to get several other examples.

Otherwise, I think you are already on the right track as long as you catch all the edge cases.

like image 70
Richard Neish Avatar answered Dec 09 '25 03:12

Richard Neish



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!