java 日期数字格式化 SimpleDateFormat("yyyy-MM-dd HH:mm:ss");等等可以看下http://blog.csdn.net/wyp164/article/details/1625980 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://www.cnblogs.com/edwardlauxh/archive/2010/03/21/1918615.html看看这个。 一Date Format1.1 SimpleDateFormat // hh小写为12小时制;注意大小写有影响的!! SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String date = sd.format(new Date()); /** 2014-06-02 09:52:59 **/1.2 DateFormat /** * // 日期时间格式 DateFormat.FULL; DateFormat.LONG; DateFormat.MEDIUM; DateFormat.SHORT; 日期类型: FULL 2014年6月1日 星期日 LONG 2014年6月1日 MEDIUM 2014-6-1 SHORT 14-6-1 时间 FULL 上午09时56分10秒 CST LONG 上午09时56分27秒 MEDIUM 9:56:42 SHORT 上午9:56 */public void test1() throws Exception { String str = "2014-6-1 上午09时56分27秒"; // 确定是那种地区的时间显示 DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.MEDIUM, Locale.CHINA); // 转化为Date类型 Date date = df.parse(str); System.out.println(date); // 把时间格式化 String date1 = df.format(new Date()); System.out.println(date1); }二 Number Format2.1 Number/Currency/tPercent @Test public void test1() throws Exception { NumberFormat nf1 = NumberFormat.getNumberInstance(Locale.US); System.out.println(nf1.format(10000)); /** 10,000 **/ NumberFormat nf2 = NumberFormat.getCurrencyInstance(Locale.US); System.out.println(nf2.format(10000)); /** $10,000.00 **/ NumberFormat nf3 = NumberFormat.getPercentInstance(Locale.US); System.out.println(nf3.format(0.2)); /** 20% **/ }2.2 Example//1.3 国际化多个数据 public void format_message() throws ParseException { // 格式化: 日期,中文; 金额,显示中文 String str = "on {0}, a hurricance destroyed 99 houses and caused {1} of damage"; String s1 = "Jul 3, 1998 12:30 PM"; String s2 = "$1000000"; //s1 转换Date DateFormat df = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT, Locale.US); Date s1_date = df.parse(s1); //s2转换为数字 NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US); Number s2_num = nf.parse(s2); // 国际化信息(多个内容) MessageFormat mf = new MessageFormat(str); // 占位符对应的值 Object[] obj = { DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.FULL, Locale.CHINA).format(s1_date), NumberFormat.getCurrencyInstance(Locale.CHINA).format(s2_num) }; // 对多个内容进行国际化 String result_str = mf.format(obj); // 国际化的字符串 System.out.println(result_str); }三 国际化3.1 ResourceBundle <% // 获取语言环境对象 Locale locale = request.getLocale(); // 加载资源包 ResourceBundle bunble = ResourceBundle.getBundle("msg",locale); %> <title><%=bunble.getString("title") %></title>3.2 JSTL国际化 <!-- 1. 设置语言环境 --> <fmt:setLocale value="${pageContext.request.locale}"/> <!-- 2. 加载资源包: basename,属性文件文件名, 需要带上包名 --> <fmt:setBundle basename="cn/itcast/fmt/msg" var="b"/> <title><fmt:message bundle="${b}" key="title"></fmt:message></title> apache下的commons-lang工具包,下面有DateFormatUtils.format用于把Date对象格式化成字符串.DateUtils.parseDate用于把字符串格式化成Date对象. String.getBytes().length每台机器上得到的值为什么不同 java中读取数字问题 APPLET中的list、button必须要在 start()函数执行完后才能显示? 救急:jsp页面如何带参数跳转到action中? 写表达式 websphere连接mysql的问题(急用在线等待,up有分) 哪有关于JVM如何运行的资料?高分回送 求高手给小弟一段可以把人物可以从色差较大的背景色中抠出来的java代码,小弟不胜感激!! 超急:关于数据插入的问题 关于“创建重载现存方法的方法” 小白看了一个简单的程序一上午,求助 菜鸟泛型求解答
看看这个。
1.1 SimpleDateFormat
// hh小写为12小时制;注意大小写有影响的!!
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String date = sd.format(new Date());
/** 2014-06-02 09:52:59 **/
1.2 DateFormat
/**
* // 日期时间格式
DateFormat.FULL;
DateFormat.LONG;
DateFormat.MEDIUM;
DateFormat.SHORT;
日期类型:
FULL 2014年6月1日 星期日
LONG 2014年6月1日
MEDIUM 2014-6-1
SHORT 14-6-1
时间
FULL 上午09时56分10秒 CST
LONG 上午09时56分27秒
MEDIUM 9:56:42
SHORT 上午9:56
*/public void test1() throws Exception {
String str = "2014-6-1 上午09时56分27秒";
// 确定是那种地区的时间显示
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL,
DateFormat.MEDIUM, Locale.CHINA);
// 转化为Date类型
Date date = df.parse(str);
System.out.println(date);
// 把时间格式化
String date1 = df.format(new Date());
System.out.println(date1);
}二 Number Format
2.1 Number/Currency/tPercent
@Test
public void test1() throws Exception {
NumberFormat nf1 = NumberFormat.getNumberInstance(Locale.US);
System.out.println(nf1.format(10000));
/** 10,000 **/ NumberFormat nf2 = NumberFormat.getCurrencyInstance(Locale.US);
System.out.println(nf2.format(10000));
/** $10,000.00 **/ NumberFormat nf3 = NumberFormat.getPercentInstance(Locale.US);
System.out.println(nf3.format(0.2));
/** 20% **/
}2.2 Example
//1.3 国际化多个数据
public void format_message() throws ParseException {
// 格式化: 日期,中文; 金额,显示中文
String str = "on {0}, a hurricance destroyed 99 houses and caused {1} of damage";
String s1 = "Jul 3, 1998 12:30 PM";
String s2 = "$1000000";
//s1 转换Date
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT, Locale.US);
Date s1_date = df.parse(s1);
//s2转换为数字
NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);
Number s2_num = nf.parse(s2);
// 国际化信息(多个内容)
MessageFormat mf = new MessageFormat(str);
// 占位符对应的值
Object[] obj = {
DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.FULL, Locale.CHINA).format(s1_date),
NumberFormat.getCurrencyInstance(Locale.CHINA).format(s2_num)
};
// 对多个内容进行国际化
String result_str = mf.format(obj);
// 国际化的字符串
System.out.println(result_str);
}三 国际化
3.1 ResourceBundle
<%
// 获取语言环境对象
Locale locale = request.getLocale();
// 加载资源包
ResourceBundle bunble = ResourceBundle.getBundle("msg",locale);
%>
<title><%=bunble.getString("title") %></title>3.2 JSTL国际化
<!-- 1. 设置语言环境 -->
<fmt:setLocale value="${pageContext.request.locale}"/>
<!-- 2. 加载资源包: basename,属性文件文件名, 需要带上包名 -->
<fmt:setBundle basename="cn/itcast/fmt/msg" var="b"/>
<title><fmt:message bundle="${b}" key="title"></fmt:message></title>
DateUtils.parseDate用于把字符串格式化成Date对象.