设为首页 加入收藏

TOP

开发中日常操作转化工具类(二)
2014-11-24 12:02:24 】 浏览:1923
Tags:开发 日常 操作 转化 工具
return str;
}
}
/**
* 移除结尾的逗号
*
*/
public static String removeEnd(String str)
{
if (str == null)
{
return "";
}
else
{
Matcher matcher = Pattern.compile(",+$").matcher(str);
str = matcher.replaceAll("");
return str;
}
}
/**
* 格式化日期
* @param date 日期
* @param pattern 格式
* @return String String
*/
public static String formatDate(Date date, String pattern)
{
SimpleDateFormat format = new SimpleDateFormat(pattern);
return format.format(date);
}
/**
* 〈计算两个日期相差的天数〉
* 〈功能详细描述〉
* @param begin 开始日期
* @param end 结束日期
* @return long
*/
public static long calDays(Date begin, Date end)
{
long time = end.getTime() - begin.getTime();
long days = time / 24 / 60 / 60 / 1000;
return days;
}
/**
* 获取未来第几天的时间yyyy-MM-dd
* @param dayNum
* @return
*/
public static String getNextDay(int dayNum){
Calendar cal = Calendar.getInstance();
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String returnDate ="";
try
{
cal.setTime(date);
cal.add(Calendar.DATE, dayNum);
returnDate = sdf.format(cal.getTime());
}
catch (Exception e)
{
e.printStackTrace();
}
return returnDate;
}
/**
* 格式化日期
* @param str 日期字符串
* @param pattern 格式
* @return Date Date
*/
public static Date formatDate(String str, String pattern)
{
Date date = null;
try
{
SimpleDateFormat format = new SimpleDateFormat(pattern);
date = format.parse(str);
}
catch (ParseException e)
{
date = new Date();
}
return date;
}
/**
* 解析字符
*
* @param key
* key
* @param str
* str
* @return value
*/
public static String getValue(String key, String str)
{
if (key == null || str == null)
{
return "";
}
String[] strArr = str.split(",");
for (String tempStr : strArr)
{
if (key.equals(tempStr.split(":")[0]))
{
return tempStr.split(":")[1];
}
}
return "";
}
/**
* 解析字符
*
* @param key
* key
* @param str
* str
* @return value
*/
public static int getIntValue(String key, String str)
{
int result = 0;
if (str == null)
{
return result;
}
String[] strArr = str.split(",");
String value = "0";
for (String tempStr : strArr)
{
if (key.equals(tempStr.split(":")[0]))
{
value = tempStr.split(":")[1];
}
}
try
{
result = Integer.parseInt(value);
}
catch
首页 上一页 1 2 3 4 5 6 7 下一页 尾页 2/9/9
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇数学运算工具类 下一篇利用JDBC连接取数据并导入到EXCEL..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目