关于EditText中的getText()方法的返回值类型以及string的转换问题

      EditText中的getText()方法的返回值为CharSequence,如果我们想要获得string类型数据的话,需要在后边加上.toString

 

 

     另外,String类型转为int:Integer.parseInt(str);

 

               String类型转为float::Float.parseFloat(str);

 

     string和Date的相互转换

  1. DateFormat format = new SimpleDateFormat("yyyy-MM-dd");        
  2. Date date = null;   
  3. String str = null;                 
  4.            
  5. // StringDate   
  6. str = "2007-1-18";         
  7. try {   
  8.     date = format.parse(str);  // Thu Jan 18 00:00:00 CST 2007   
  9. catch (ParseException e) {   
  10.     e.printStackTrace();   
  11. }   
  12.            
  13. date = java.sql.Date.valueOf(str);  // 只保留日期部分,返回的是java.sql.Date  2007-01-18   
  14.            
  15. // DateString   
  16. date = new Date();   // Thu Jan 18 21:35:01 CST 2007   
  17. /*Calendar cal = Calendar.getInstance();  
  18. date = new Date(cal.getTimeInMillis());*/  
  19. str = format.format(date);  // 2007-01-18   
  20.            
  21. format = DateFormat.getDateInstance(DateFormat.SHORT);   
  22. str = format.format(date);  // 07-1-18   
  23.            
  24. format = DateFormat.getDateInstance(DateFormat.MEDIUM);   
  25. str = format.format(date);  // 2007-1-18   
  26.            
  27. format = DateFormat.getDateInstance(DateFormat.FULL);   
  28. str = format.format(date);  // 2007年1月18日 星期四

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值