import java.util.*; import java.util.zip.*; import java.util.List; import java.util.regex.*; import java.util.concurrent.*; import java.util.concurrent.atomic.*; import java.util.concurrent.locks.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.text.*; import javax.swing.table.*; import java.io.*; import java.net.*; import java.lang.reflect.*; import java.lang.ref.*; import java.lang.management.*; import java.security.*; import java.security.spec.*; import java.awt.*; import java.awt.event.*; import java.awt.image.*; import javax.imageio.*; import java.math.*; import java.text.*; import java.text.DecimalFormat; import java.util.TimeZone; class main { static String localTimeForSpeechOutput() { int minutes = localMinutes(); int hours = ((localHours()+11) % 12)+1; return numberToEnglish(hours) + " " + (minutes == 0 ? " o'clock" : numberToEnglish(minutes)); } static int localMinutes(long time) { SimpleDateFormat sdf = new SimpleDateFormat("mm"); sdf.setTimeZone(localTimeZone()); return parseInt(sdf.format(time)); } static int localMinutes() { return localMinutes(now()); } static int localHours(long time) { SimpleDateFormat sdf = new SimpleDateFormat("HH"); sdf.setTimeZone(localTimeZone()); return parseInt(sdf.format(time)); } static int localHours() { return localHours(now()); } // from https://www.rgagnon.com/javadetails/java-0426.html static String numberToEnglish(long number) { return numberToEnglish_EnglishNumberToWords.convert(number); } static class numberToEnglish_EnglishNumberToWords { private static final String[] tensNames = { "", " ten", " twenty", " thirty", " forty", " fifty", " sixty", " seventy", " eighty", " ninety" }; private static final String[] numNames = { "", " one", " two", " three", " four", " five", " six", " seven", " eight", " nine", " ten", " eleven", " twelve", " thirteen", " fourteen", " fifteen", " sixteen", " seventeen", " eighteen", " nineteen" }; private static String convertLessThanOneThousand(int number) { String soFar; if (number % 100 < 20){ soFar = numNames[number % 100]; number /= 100; } else { soFar = numNames[number % 10]; number /= 10; soFar = tensNames[number % 10] + soFar; number /= 10; } if (number == 0) return soFar; return numNames[number] + " hundred" + soFar; } public static String convert(long number) { // 0 to 999 999 999 999 if (number == 0) { return "zero"; } String snumber = Long.toString(number); // pad with "0" String mask = "000000000000"; DecimalFormat df = new DecimalFormat(mask); snumber = df.format(number); // XXXnnnnnnnnn int billions = Integer.parseInt(snumber.substring(0,3)); // nnnXXXnnnnnn int millions = Integer.parseInt(snumber.substring(3,6)); // nnnnnnXXXnnn int hundredThousands = Integer.parseInt(snumber.substring(6,9)); // nnnnnnnnnXXX int thousands = Integer.parseInt(snumber.substring(9,12)); String tradBillions; switch (billions) { case 0: tradBillions = ""; break; case 1 : tradBillions = convertLessThanOneThousand(billions) + " billion "; break; default : tradBillions = convertLessThanOneThousand(billions) + " billion "; } String result = tradBillions; String tradMillions; switch (millions) { case 0: tradMillions = ""; break; case 1 : tradMillions = convertLessThanOneThousand(millions) + " million "; break; default : tradMillions = convertLessThanOneThousand(millions) + " million "; } result = result + tradMillions; String tradHundredThousands; switch (hundredThousands) { case 0: tradHundredThousands = ""; break; case 1 : tradHundredThousands = "one thousand "; break; default : tradHundredThousands = convertLessThanOneThousand(hundredThousands) + " thousand "; } result = result + tradHundredThousands; String tradThousand; tradThousand = convertLessThanOneThousand(thousands); result = result + tradThousand; // remove extra spaces! return result.replaceAll("^\\s+", "").replaceAll("\\b\\s{2,}\\b", " "); } } static TimeZone localTimeZone() { return getTimeZone(standardTimeZone()); // TimeZone.getDefault()? } static int parseInt(String s) { return emptyString(s) ? 0 : Integer.parseInt(s); } static int parseInt(char c) { return Integer.parseInt(str(c)); } static long now_virtualTime; static long now() { return now_virtualTime != 0 ? now_virtualTime : System.currentTimeMillis(); } static TimeZone getTimeZone(String name) { return TimeZone.getTimeZone(name); } static String standardTimeZone_name = "Europe/Berlin"; static String standardTimeZone() { return standardTimeZone_name; } static boolean emptyString(String s) { return s == null || s.length() == 0; } static String str(Object o) { return o == null ? "null" : o.toString(); } static String str(char[] c) { return new String(c); } }