1.如何求两个整数的百分比
- int currentindex = 55;
- int totalcount = 66;
- NumberFormat nf = NumberFormat.getPercentInstance();
- 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.从一个链接中获取域名
- 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());
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.显示年月日时分秒星期
- Date date = new Date();
- SimpleDateFormat dateformat = new SimpleDateFormat(
- "yyyy年MM月dd日 HH时mm分ss秒 E");
- String dateStr = dateformat.format(date);
- 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.显示年月日时分秒毫秒
- Date date = new Date();
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日HH时mm分ss秒SSS");
- String dateStr = sdf.format(date);
- 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);