Java实现将数字日期翻译成英文单词的工具类实例实现将数字日期翻译成英文单词的工具类实例
主要介绍了Java实现将数字日期翻译成英文单词的工具类,结合完整实例形式分析了Java日期转换与字符串操作相关实现技巧,需要的朋友可以参考下
本文实例讲述了Java实现将数字日期翻译成英文单词的工具类。分享给大家供大家参考,具体如下:
package com.sunyard.etp.ag.util;
import java.math.BigDecimal;
import java.util.Arrays;
public class DateEngUtil {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String dd="19870401";
String res=formatDateEng(dd);
System.out.println(dd+",英文==="+res);
String dd2="19000823";
String res2=formatDateEng(dd2);
System.out.println(dd2+",英文==="+res2);
String dd3="20001231";
String res3=formatDateEng(dd3);
System.out.println(dd3+",英文==="+res3);
String dd4="20121116";
String res4=formatDateEng(dd4);
System.out.println(dd4+",英文==="+res4);
String dd5="20150901";
String res5=formatDateEng(dd5);
System.out.println(dd5+",英文==="+res5);
/*
19870401,英文===nineteen eighty seven, April, first
19000823,英文===nineteen hundred, August, twenty third
20001231,英文===two thousand, December, thirty first
20121116,英文===two thousand and twelve, November, sixteenth
20150901,英文===two thousand and fifteen, September, first
*/
//支持最多4位数字的翻译
String nn1="12";
String r1=translateNum9999NoZero(nn1);
System.out.println(nn1+",英文==="+r1);
String nn2="561";
String r2=translateNum9999NoZero(nn2);
System.out.println(nn2+",英文==="+r2);
String nn3="5589";
String r3=translateNum9999NoZero(nn3);
System.out.println(nn3+",英文==="+r3);
/*
12,英文===twelve
561,英文===five hundred and sixty one
5589,英文===five thousand five hundred and eighty nine
*/
String cardNum="6210910002000718183";
String cardn=translateCardNumber(cardNum);
System.out.println(cardNum+",英文==="+cardn);
/*
6210910002000718183,英文=== six two one zero nine one zero zero zero two zero zero zero seven one eight one eight three
*/
String fff="3394.56";
System.out.println("钱"+fff+"==="+translateMoney(fff));
String fff2="123456789123456.45";
System.out.println("钱"+fff2+"==="+translateMoney(fff2));
String fff3="78.00";
System.out.println("钱"+fff3+"==="+translateMoney(fff3));
String fff4="12000089103456.45";
System.out.println("钱"+fff4+"==="+translateMoney(fff4));
String fff5="123456789.12";
System.out.println("钱"+fff5+"==="+translateMoney(fff5));
/*
钱3394.56===three thousand, three hundred and ninety four point five six
钱123456789123456.45===one hundred and twenty three trillion, four hundred and fifty six billion, seven hundred and eighty nine million, one hundred and twenty three thousand, four hundred and fifty six point four five
钱78.00===seventy eight point zero zero
钱12000089103456.45===twelve trillion, eighty nine million, one hundred and three thousand, four hundred and fifty six point four five
钱123456789.12===one hundred and twenty three million, four hundred and fifty six thousand, seven hundred and eighty nine point one two
*/
String p1="0%";
System.out.println("百分比"+p1+"==="+translatePercent(p1));
String p2="0.0%";
System.out.println("百分比"+p2+"==="+translatePercent(p2));
String p3="0.00%";
System.out.println("百分比"+p3+"==="+translatePercent(p3));
String p4="0.23%";
System.out.println("百分比"+p4+"==="+translatePercent(p4));
String p5="0.05%";
System.out.println("百分比"+p5+"==="+translatePercent(p5));
String p6="56.00%";
System.out.println("百分比"+p6+"==="+translatePercent(p6));
String p7="56.67%";
System.out.println("百分比"+p7+"==="+translatePercent(p7));
String p8="237.90%";
System.out.println("百分比"+p8+"==="+translatePercent(p8));
/*
百分比0%===zero point zero zero percent
百分比0.0%===zero point zero zero percent
百分比0.00%===zero point zero zero percent
百分比0.23%=== zero point two three percent
百分比0.05%=== zero point zero five percent
百分比56.00%===fifty six point zero zero percent
百分比56.67%===fifty six point six seven percent
百分比237.90%===two hundred and thirty seven point nine zero percent
*/
}
/**
* 格式化日期
*
* @return
*
*/
public static String formatDate(String Date){
try{
return Date.substring(0,4)+"年"+Date.substring(4,6)+"月"+Date.substring(6,8)+"日";
}catch (Exception e) {