// (c) F. Merciol
// Plus d'informations sur http://m3101.merciol.fr
package io;

import java.text.ChoiceFormat;
import java.text.MessageFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class TestFormat {

		public static void main(String[] args) {
				try {
				SimpleDateFormat sdf = new SimpleDateFormat ("dd MM HH:mm ");
				System.out.println (sdf.format (new Date ()));

				ChoiceFormat cf = new ChoiceFormat ("-1# negatif|0#nul|1#un|1<plusieurs");
				for (int i : new int[]{-1, 0, 1, 2}) {
						System.out.println (i+" => "+cf.format (i));
				}

				MessageFormat mf =
						new MessageFormat ("Phrase avec "+
															 "un nombre {0,number,integer}, "+
															 "un mot {2} une date {1,date}, "+
															 "une heure {1,time}.");
				Object[] objs = {42, new Date (), "super"};
				String s = mf.format (objs);
				System.out.println (s);

				Object[] result = mf.parse (s);
				for (Object obj : result)
						System.out.println (" => "+obj);
				} catch (ParseException e) {
				}
		}
}
