java常用格式转换_java的类型转换(常用字符串,日期,汉字符号等!!)

一.常用数据类型转换

other to String

public static void main(String[] args) {

int m=110;

String s=String.valueOf(m);

System.out.println(s);

}

String to other(int,float,doubble,,,,);

公式:other i=other.parseother(String);

String to Date

公式:SimpleDateFormat sd=new SimpleDateFormat(yyyy-MM-dd(日期格式))

Date date=sd.parse(String);

Date to String

公式:String string=sd.format(Date);

二。日期类型之间的转换

sql.Date= new sql.Date(util.Date.getTime());

三。汉字字符的转换;

方法one: 在Servlet的接受语句中,将该语句的接受对象(设为string),做如下操作:

方法two:标准写法,在接受数据的页面之前,加上四大基础对象之一的filter(过滤器),

在dofilter方法中,加入如下语句:

request。setcharacterEncoding(“UTF-8”);

之后在web。xmail,中配置如下信息:

filtername

filter的位置

filtername

/web地址(*所有的页面都过滤)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值