国际化 格式化

1、请编写一个能国际化显示的登陆页面



<%@ page Xlanguage="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
 <base href="<%=basePath%>">
 
<title>My JSP 'Second.jsp' starting page</title>
 
<meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="cache-control" content="no-cache">
 <meta http-equiv="expires" content="0"> 
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 <meta http-equiv="description" content="This is my page">
 <!--
 <link rel="stylesheet" type="text/css" href="styles.css">
 -->
 
</head>
 
<body>
 <fmt:setLocale value="zh"/>
 <fmt:setBundle basename="com.csdn.hbsi.Resource.myresource"/>
 <form action="">
 <fmt:message key="username"/>
 <input type="text" name="username">
 <br>
 <fmt:message key="password"/>
 <input type="password" name="password">
 <br>
 <input type="submit" value=""/>
 </form>
 </body>
</html>








 
2、请创建一个date对象,并把date对象中表示日期部分的时间值,以及表示时间部分的时间值,分别以short、long模式进行格式化输出(国家设置为中国)。
 
package com.csdn.hbsi.test;
 
import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;
 
public class Demo2 {
 
/**
 * @param args
 */
 public static void main(String[] args) {
 Date d=new Date();
 DateFormat df=DateFormat.getDateInstance(DateFormat.SHORT,Locale.CHINA);
 String result=df.format(d);
 System.out.println(result);
 
df=DateFormat.getTimeInstance(DateFormat.LONG,Locale.CHINA);
 result=df.format(d);
 System.out.println(result);
 }
 
}


 






3、请将时间值:09-11-28 上午10时25分39秒 CST,反向解析成一个date对象。


package com.csdn.hbsi.test;

 
import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;
import java.util.Locale;
 
public class Demo3 {
 
/**
 * @param args
 */
 public static void main(String[] args) {
 String s="09-11-28 上午10时25分39秒 CST";
 DateFormat df=DateFormat.getTimeInstance(DateFormat.FULL, Locale.CHINA);
 try {
 Date d=df.parse(s);
 System.out.println(d);
 } catch (ParseException e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 }
 }
 
}









 
4、请将整数198,输出为货币形式:$198,并将$198反向解析成整数198。
 
package com.csdn.hbsi.test;
 
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Locale;
 
public class huobi {
 
/**
 * @param args
 * @throws ParseException 
*/
 public static void main(String[] args) throws ParseException {
 double db=198;
 
NumberFormat nf=NumberFormat.getCurrencyInstance(Locale.US);
 String result=nf.format(db);
 System.out.println(result);
 
 String s="$198";
 nf=NumberFormat.getCurrencyInstance(Locale.US);
 Number n=nf.parse(s);
 double db1=n.doubleValue();
 System.out.println(db1);
 



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值