位置: 编程技术 - 正文

工具类(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各版本的兼容方法类(工具类软件有哪些)

  • 用于员工福利的进项税转出分录
  • 借贷记账法的基本结构
  • 增量留底退税好处
  • 支付宝过路费开票小程序
  • 设备租赁合同需要审核吗
  • 折旧四种方法
  • 企业外包项目如何确认收入成本配比?
  • 工厂临时住宿
  • 广告媒体类的企业怎么核算成本?
  • 印花税缴纳后合计怎么算
  • 工程施工企业人工成本最高多少
  • 支付给职工和为职工支付的现金
  • 跨月负数发票会计分录
  • 民办非企业单位设立分机构
  • 税收分类编码风险评估
  • 如何处理取得的失控发票增值税和企业所得税?
  • 开具的增值税专用发票上注明的价款为50万元
  • 企业所得税汇算清缴
  • 出口公司代理
  • 地方教育费附加的会计分录
  • 汽车修理费抵扣怎么做账
  • 预提返利的会计处理
  • 简单介绍linux
  • linux禁用root用户
  • 销售回款率怎么计算
  • 如何查询公司有没有报个税
  • 收到负数发票怎么办
  • 发票已认证还未开票
  • 物流丢失了货品如何报警处理
  • windows账户名a
  • 政府性基金收入是政府非税收入吗
  • 购入固定资产后发生的员工培训费应计入固定资产的成本
  • PHP:Memcached::delete()的用法_Memcached类
  • php课堂笔记
  • undetected_chromedriver下载
  • 货物运输税费
  • 预缴企业所得税分录
  • 深度学习实战——不同方式的模型部署(CNN、Yolo)
  • smarty模板注入
  • php中类静态成员描述不正确的是
  • php读取word内容
  • 金蝶利息收入结转怎么弄
  • 资产负债表各项目年初余额栏内各项数字
  • 什么是多模态研究
  • 以固定资产抵账什么意思
  • 出租人经营租赁会计分录
  • 什么是企业所得税收入
  • 营改增分录
  • 未开票收入缴纳增值税怎么冲减补开发票
  • 国债逆回购收益什么时候到账
  • 从外面买回来的鸡蛋能孵出小鸡吗
  • 出资注意事项有哪些内容
  • 工作经费是什么
  • 旅游发票可以报销入什么明细
  • 职工福利费和工会经费
  • 分公司与总公司的责任承担
  • 小规模纳税人超过30万是全额纳税吗
  • 没有认证的进项发票可以做成本吗
  • 收不回来的其他应收款如何坏账处理
  • 安装完xp系统直接蓝屏怎么办
  • 怎么通过mac连接wifi
  • linux常用配置
  • win7开机屏幕狂闪不停怎么解决
  • unity3d怎么用
  • FreeGLUT Tips: Resolve compile issue: error LNK1104: cannot open file 'freeglutd.lib'
  • es6数组函数
  • android图片布局
  • Androidannotation使用之@Rest获取资源及用户登录验证(一)
  • 手机背光面板
  • android下拉刷新上拉加载
  • android设置背景颜色代码
  • 如何进行前后端交互
  • 增值税普通发票可以抵扣吗
  • 中国裁判文书怎么查个人案件
  • 出口退的增值税怎么算
  • 贵州电子税务局app下载
  • 税务部门政务公开
  • 陕西税务干部学校副教授李刚简历
  • 行政单位,比如什么单位
  • 加油的增值税发票可以抵扣吗
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设