import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;

import org.apache.commons.cli.*;


/**
 * CLI̗K
 */
public class DateApp {

	public static void main(String[] args) {

		Options options = new Options();
		options.addOption("t", false, "display current time");
		//options.addOption("c", true, "by locale");
		options.addOption(OptionBuilder
								.withArgName("locale")
		                        .hasArg()
                                .withDescription(  "with locale" )
                                .create( "c") );

		
		options.addOption("h", false, "display help");
		
		CommandLineParser parser 
			= new BasicParser();
			//= new PosixParser();
			//= new GnuParser();

		try {
			CommandLine cl = parser.parse(options, args);


			if(cl.hasOption("h") ){
				HelpFormatter formatter = new HelpFormatter();
				formatter.printHelp( "Test1", options, true);
				return;
			}

			DateFormat df;
			Locale locale;

			String countryCode = cl.getOptionValue("c");
			if (countryCode == null) {
				locale = Locale.getDefault();
			} else {
				locale = new Locale(countryCode);
			}

			if (cl.hasOption("t")) {
				df = DateFormat.getTimeInstance(DateFormat.FULL, locale);
			} else {
				df = DateFormat.getDateInstance(DateFormat.FULL, locale);
			}

			System.out.println(df.format(new Date()));

		} catch (ParseException e) {
			e.printStackTrace();
		}

	}
}
