位置: 编程技术 - 正文

工具类(6) 字符串操作工具类(工具类别怎么填写)

编辑:rootadmin
public class StringUtils {private final static Pattern emailer = Pattern.compile("\w&#;([-&#;.]\w&#;)*@\w&#;([-.]\w&#;)*\.\w&#;([-.]\w&#;)*");// private final static SimpleDateFormat dateFormater = new// SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// private final static SimpleDateFormat dateFormater2 = new// SimpleDateFormat("yyyy-MM-dd");private final static ThreadLocal<SimpleDateFormat> dateFormater = new ThreadLocal<SimpleDateFormat>() {@Overrideprotected SimpleDateFormat initialValue() {return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");}};private final static ThreadLocal<SimpleDateFormat> dateFormater2 = new ThreadLocal<SimpleDateFormat>() {@Overrideprotected SimpleDateFormat initialValue() {return new SimpleDateFormat("yyyy-MM-dd");}};/*** 将字符串转位日期类型* * @param sdate* @return*/public static Date toDate(String sdate) {try {return dateFormater.get().parse(sdate);} catch (ParseException e) {return null;}}/*** 以友好的方式显示时间* * @param sdate* @return*/public static String friendly_time(String sdate) {Date time = toDate(sdate);if (time == null) {return "Unknown";}String ftime = "";Calendar cal = Calendar.getInstance();// 判断是否是同一天String curDate = dateFormater2.get().format(cal.getTime());String paramDate = dateFormater2.get().format(time);if (curDate.equals(paramDate)) {int hour = (int) ((cal.getTimeInMillis() - time.getTime()) / );if (hour == 0)ftime = Math.max((cal.getTimeInMillis() - time.getTime()) / , 1)&#; "分钟前";elseftime = hour &#; "小时前";return ftime;}long lt = time.getTime() / ;long ct = cal.getTimeInMillis() / ;int days = (int) (ct - lt);if (days == 0) {int hour = (int) ((cal.getTimeInMillis() - time.getTime()) / );if (hour == 0)ftime = Math.max((cal.getTimeInMillis() - time.getTime()) / , 1)&#; "分钟前";elseftime = hour &#; "小时前";} else if (days == 1) {ftime = "昨天";} else if (days == 2) {ftime = "前天";} else if (days > 2 && days <= ) {ftime = days &#; "天前";} else if (days > ) {ftime = dateFormater2.get().format(time);}return ftime;}/*** 判断给定字符串时间是否为今日* * @param sdate* @return boolean*/public static boolean isToday(String sdate) {boolean b = false;Date time = toDate(sdate);Date today = new Date();if (time != null) {String nowDate = dateFormater2.get().format(today);String timeDate = dateFormater2.get().format(time);if (nowDate.equals(timeDate)) {b = true;}}return b;}/*** 返回long类型的今天的日期* @return*/public static long getToday() {Calendar cal = Calendar.getInstance();String curDate = dateFormater2.get().format(cal.getTime());curDate = curDate.replace("-", "");return Long.parseLong(curDate);}/*** 判断给定字符串是否空白串。 空白串是指由空&#;、制表符、回车符、换行符组成的字符串 若输入字符串为null或空字符串,返回true* * @param input* @return boolean*/public static boolean isEmpty(String input) {if (input == null || "".equals(input))return true;for (int i = 0; i < input.length(); i&#;&#;) {char c = input.charAt(i);if (c != ' ' && c != 't' && c != 'r' && c != 'n') {return false;}}return true;}/*** 判断是不是一个合法的电子邮件地址* * @param email* @return*/public static boolean isEmail(String email) {if (email == null || email.trim().length() == 0)return false;return emailer.matcher(email).matches();}/*** 字符串转整数* * @param str* @param defValue* @return*/public static int toInt(String str, int defValue) {try {return Integer.parseInt(str);} catch (Exception e) {}return defValue;}/*** 对象转整数* * @param obj* @return 转换异常返回 0*/public static int toInt(Object obj) {if (obj == null)return 0;return toInt(obj.toString(), 0);}/*** 对象转整数* * @param obj* @return 转换异常返回 0*/public static long toLong(String obj) {try {return Long.parseLong(obj);} catch (Exception e) {}return 0;}/*** 字符串转布尔&#;* * @param b* @return 转换异常返回 false*/public static boolean toBool(String b) {try {return Boolean.parseBoolean(b);} catch (Exception e) {}return false;}/*** 将一个InputStream流转换成字符串* @param is* @return*/public static String toConvertString(InputStream is) {StringBuffer res = new StringBuffer();InputStreamReader isr = new InputStreamReader(is);BufferedReader read = new BufferedReader(isr);try {String line;line = read.readLine();while (line != null) {res.append(line);line = read.readLine();}} catch (IOException e) {e.printStackTrace();} finally {try {if (null != isr) {isr.close();isr.close();}if (null != read) {read.close();read = null;}if (null != is) {is.close();is = null;}} catch (IOException e) {}}return res.toString();}}

推荐整理分享工具类(6) 字符串操作工具类(工具类别怎么填写),希望有所帮助,仅作参考,欢迎阅读内容。

工具类(6) 字符串操作工具类(工具类别怎么填写)

文章相关热门搜索词:工具类的东西有哪些,工具类什么意思,工具类的词语有哪些,工具俩字,工具类有哪些种类,工具类名称,工具类怎么写,工具类怎么写,内容如对您有帮助,希望把文章链接给更多的朋友!

工具类(5)Android各版本的兼容方法类 publicclassMethodsCompat{@TargetApi(5)publicstaticvoidoverridePendingTransition(Activityactivity,intenter_anim,intexit_anim){activity.overridePendingTransition(enter_anim,exit_anim);}@TargetApi(7)publ

工具类(4)图片操作工具类 本工具类又开源项目中获得publicclassImageUtils{publicfinalstaticStringSDCARD_MNT=/mnt/sdcard;publicfinalstaticStringSDCARD=/sdcard;/**请求相册*/publicstaticfinalintREQUEST_CODE_GETIMAGE

PC获取手机截图、复制文件、安装APK 我在eoe上的帖子的链接PC获取手机截图、复制文件、安装

标签: 工具类别怎么填写

本文链接地址:https://www.jiuchutong.com/biancheng/384298.html 转载请保留说明!

上一篇:Android开源项目(非组件)(android 开源)

下一篇:工具类(5)Android各版本的兼容方法类(工具类软件有哪些)

  • 税款所属期
  • 外贸企业指的是什么
  • 外出经营涉税事项报告
  • 期间费用的界定
  • 商贸公司可以做美容行业吗?
  • 固定资产出租的收入计入什么科目
  • 小企业固定资产折旧方法
  • 增值税负数如何计算
  • 咨询费可以入账吗
  • 代驾公司增值税怎么交
  • 金税盘全额抵扣分录
  • 机打发票领回怎么录入
  • 关于不动产进项税额分期抵扣的新政策,以下不属于
  • 预缴所得税需要结转吗
  • 费用结转到本年利润是手动还自动结转?
  • 分公司负债,总公司要负担
  • 银行转账结算凭证按照填制手续和内容
  • 增值税减免附加税用计提吗
  • 小微企业增值税优惠政策最新2022
  • 资本的不同形态
  • 劳务公司开具劳务费发票
  • linux 创建sh
  • 财务清算的作用
  • 开出发票单位收到款项如何平账?
  • 木星应该涂什么颜色
  • 固定资产置换存货的账务处理
  • 银行转来委托收款
  • php curl命令详解
  • 深度强化学习-DQN算法原理与代码
  • html的标签大全
  • chkconfig命令参数
  • php读取文件内容
  • 高速过路费电子发票怎么开
  • 经销商自用车是指什么
  • phpcms官网打不开
  • 涉税金额是指金额还是税额
  • 年终奖发放有法律规定吗
  • 几个项目可以合到一起招标吗
  • 什么是服务型
  • 纳税人识别号是不是税号
  • 企业适用的增值税税率
  • 长期股权投资的账面价值怎么计算
  • 税控系统技术维护费会计处理280
  • 当月业务的发票可以次月开吗
  • 与广告公司签个协议
  • 阶段性减免社保费政策期限延长
  • 零余额账户用款额度是什么意思
  • 政府会计双核算模式的好处
  • 双方投资合作项目合法吗
  • 投资收益属于什么科目,借贷方向
  • 社保稳岗补贴账务处理分录
  • 免税申请需要什么材料
  • 取得投资款缴纳企业所得税吗
  • 为别人开发票先收的税金怎么入帐?
  • 余额调节表的模板
  • 税务局三代手续费是什么
  • 手机属于固定资产吗
  • 如何在境外银行开户
  • mac电脑拷贝文件在哪里
  • freebsd使用
  • ati2sgag.exe进程安全吗 ati2sgag进程信息查询
  • 第一次安装ps后需要哪些设置
  • linux进程管理实验总结
  • mssvr.exe - mssvr是什么进程 什么用
  • win7系统无法更改主题
  • 嵌入式linux开发用什么语言
  • linux怎样使用
  • python爬取教程
  • android:View的setTag和getTag使用
  • css翻转正反面
  • xcode 导入sdk
  • 用球体模拟天空的游戏
  • c# opengl 3d
  • nodejs 调用命令行
  • android DefaultHttpClient设置setCookieStore
  • jquery的css方法
  • vue卡片式风格
  • 个体工商户税务年报网上怎么申报
  • 个人经营所得定率征收税率表
  • 国家税务局何时上班
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设