2
    import java.text.*; //SimpleDateFormat
    import java.util.*; //Date

    class MyClass
    {
        public static void main (String[] args)
        {
            SimpleDateFormat sdt = new SimpleDateFormat ("d-y-M");
            Date today = new Date();

            String msg = sdt.format(today);

            System.out.println(msg);
        }
    }

This code gives output : "31-2012-12".. but I want as below : "Thirty One - Two thousand twelve - Twelve"..

bonCodigo
  • 14,268
  • 1
  • 48
  • 91
Bhushankumar Lilapara
  • 780
  • 1
  • 13
  • 26
  • 1
    I'd create something that parses the numbers and creates this text personally. I dont think there is anything in the core libraries that do this and it shouldnt be too hard to do yourself – RNJ Dec 31 '12 at 15:39
  • http://www.roseindia.net/answers/viewqa/Java-Beginners/24697-convert-date-month-and-year-into-word-using-java.html has some rather C like code to do this for you – RNJ Dec 31 '12 at 15:40
  • 2
    You may convert it to a number then use this post as a reference : http://stackoverflow.com/questions/3911966/how-to-convert-number-to-words-in- to convert the numbers to words. – bonCodigo Dec 31 '12 at 15:40
  • Yep, I made my own quite easily – tckmn Dec 31 '12 at 15:40
  • 1
    @RNJ Yep I am agree, I think better to use Enum – Chandana Dec 31 '12 at 15:44
  • +1 for proposing `Enum` :) – bonCodigo Dec 31 '12 at 15:48

2 Answers2

2

Adding my comment as an asnwer:

You may convert it to a number then use this post as a reference: How to convert number to words in java to convert numbers to words.

Community
  • 1
  • 1
bonCodigo
  • 14,268
  • 1
  • 48
  • 91
0

http://cboard.cprogramming.com/c-programming/44180-converting-numbers-words.html

It's a C algorithm, but it should give you the idea. Please, next time try to show a bit of effort before submitting a question.

Alessandro Santini
  • 1,943
  • 13
  • 17