位置: 编程技术 - 正文

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

  • 本期收入和本期免税收入有什么区别
  • 个体经营所得税核定征收2023标准
  • 收到税务局退款怎么做分录
  • 海关缴款书有效期多久
  • 所有者权益股东权益
  • 个人收到利息要交增值税吗为什么
  • 无法支付的应付款怎么处理
  • 公司代垫个税会计分录
  • 合作社增值税免税项目
  • 付城镇土地使用税是多少
  • 收到一达通退税款怎么做账
  • 产品销售员
  • 销售商品确认收入的时间
  • 股权转让的溢价要交什么税
  • 从国内往国外寄东西要多久
  • 超市的发票是什么种类
  • 装修费属于劳务费吗
  • 公司自持物业所承担的土地出让金是否可以抵扣呢?
  • 企业不重视引起的四大涉税风险
  • 未开票收入可以填写负数吗
  • 发票代码不是10位,怎么提示输入12位的
  • 收到股息红利免征增值税
  • 增值税普通发票和普通发票的区别怎么交税
  • 资产类科目余额在借方表示什么
  • 银行对公账户网上注销流程需要多久
  • 供应商给客户员工回扣有罪吗
  • 虚开普票是不是很普遍
  • 出口货物免抵退税额确认会计分录
  • 土地无形资产怎么估值
  • 非应纳增值税项目
  • 电费发票和实际交的钱不一样怎样支付
  • 哪些固定资产不会随着时间的流逝贬值
  • linux系统已经得到了广泛的应用
  • nuxt怎么用
  • 抖音小程序任务哪里接
  • 计算完工产品成本
  • 日本东京秋叶原攻略
  • 常见浏览器兼容软件
  • 什么是前后端分离的方式
  • 前端从后端拿excel文件
  • controller控制器怎么调
  • python里pip
  • vue遇到的问题和解决方法
  • 301重定向到https 并且不带www跳转到带www
  • 结构性存款随时可取么
  • 企业的所有分类
  • 生产辅助
  • 银行承兑汇票回头背书
  • sql已成功与服务器建立连接但登录中发生错误
  • 增值税加计扣除最新政策2023
  • 个体户和公司的税收相差多少
  • 固定资产丢失进哪个科目
  • 税控盘 减免
  • 当期应纳增值税税额的计算流程
  • 资产减值损失科目借方增加还是减少
  • 应收应付款会计分录
  • 现金收货款要填什么信息
  • 长期待摊费用为什么属于资产
  • 应交增值税减免税额在借方
  • 股权质押和股权抵押有什么区别
  • 公账上的钱怎么提出来
  • 小规模主营业务成本是否含税
  • 民间非盈利组织使用什么会计准则
  • 发票金额大于付款金额可以报销吗
  • 如何理解应收账款平均余额
  • 故意销毁会计凭证、会计账簿罪
  • xp windows功能在哪里
  • hyper-v怎么样
  • freebsd 配置ip
  • Windows Server AD 访问数量控制配置方法
  • ubuntu中no such file or directory
  • mac插hdmi没画面
  • linux日志数据种类
  • 设计模式三种
  • 关闭默认共享和共享文件夹
  • django自定义模板标签
  • 深入理解javascript
  • unity脚本api
  • python周期性分析
  • 拆迁房抵税政策
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设