Java 代码功能片段(待续。。。)

1.如何求两个整数的百分比

  1. int currentindex = 55;  
  2. int totalcount = 66;  
  3. NumberFormat nf = NumberFormat.getPercentInstance();  
  4. final String persent = nf.format(((float)currentindex/(float)totalcount));  
int currentindex = 55;
int totalcount = 66;
NumberFormat nf = NumberFormat.getPercentInstance();
final String persent = nf.format(((float)currentindex/(float)totalcount));


2.从一个链接中获取域名

  1. String url = "http://blog.csdn.net/zuolongsnail";  
  2. Pattern p = Pattern.compile(  
  3.         "(?<=http://|\\.)[^.]*?\\.(com|cn|net|org|biz|info|cc|tv)",  
  4.         Pattern.CASE_INSENSITIVE);  
  5. Matcher matcher = p.matcher(url);  
  6. matcher.find();  
  7. System.out.println(matcher.group());  
String url = "http://blog.csdn.net/zuolongsnail";
Pattern p = Pattern.compile(
		"(?<=http://|\\.)[^.]*?\\.(com|cn|net|org|biz|info|cc|tv)",
		Pattern.CASE_INSENSITIVE);
Matcher matcher = p.matcher(url);
matcher.find();
System.out.println(matcher.group());


3.显示年月日时分秒星期

  1. Date date = new Date();  
  2. SimpleDateFormat dateformat = new SimpleDateFormat(  
  3.         "yyyy年MM月dd日 HH时mm分ss秒 E");  
  4. String dateStr = dateformat.format(date);  
  5. System.out.println(dateStr);  
Date date = new Date();
SimpleDateFormat dateformat = new SimpleDateFormat(
		"yyyy年MM月dd日 HH时mm分ss秒 E");
String dateStr = dateformat.format(date);
System.out.println(dateStr);

4.显示年月日时分秒毫秒

  1. Date date = new Date();  
  2. SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日HH时mm分ss秒SSS");  
  3. String dateStr = sdf.format(date);  
  4. System.out.println(dateStr);  
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日HH时mm分ss秒SSS");
String dateStr = sdf.format(date);
System.out.println(dateStr);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值