位置: 编程技术 - 正文

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

发布时间:2024-02-27
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各版本的兼容方法类(工具类软件有哪些)

  • 产权转移书据印花税政策
  • 所得税损益类科目包括
  • 印花税是根据销售额提吗
  • 差旅费报销单是外来原始凭证吗
  • 销项减进项余额在哪方
  • 企业外币账户怎么开通
  • 福利费进项税转出的会计分录
  • 为什么出现补交税
  • 为什么购买的货没有发票
  • 明细分类核算的方法分为
  • 土地使用税怎么终止
  • 现金股利和股票股利的区别
  • 公司购买软件著作权
  • 增值税扣完税款还能更改吗
  • 工会经费滞纳金是多少
  • 投标保证金支付时间
  • 外贸企业当期认证的发票没申报影响退税吗?
  • 软件企业增值税退税的账务处理
  • 外贸 内销
  • 季度企业所得税可以弥补以前年度亏损吗
  • 企业所得税汇算清缴申报表
  • 车间未完工的产品属于什么
  • 用钱买的代金券怎么使用
  • 农机公司也要缴残保金吗
  • 独生子女补贴怎么查询
  • 1697510552
  • windows4月更新
  • 月末一次加权平均法是什么意思
  • 事业单位政府预算
  • 解除劳动关系取公积金
  • Win11怎么关闭自动休眠
  • win7对话框文本框在哪里
  • 如何在数据透视表中增加一行
  • 销项负数发票应该给谁
  • 在职职工医疗保障计划互助金多久发一次
  • 租金收入计入收入总额吗
  • 资产为什么等于成本
  • 固定资产折旧提完后只剩净残值
  • 停车费报销怎么做账
  • 捷税宝被稽查了吗
  • web开发 python
  • imu定位
  • 年度总产值等于营业收入
  • 接受赠品怎么做账
  • 股东转让股份会退股吗
  • 对公账号里面的钱会扣税吗
  • 对公账户每笔钱都得做账吗
  • 普票 销项
  • 小企业会计准则和一般企业会计准则的区别
  • 帐载金额
  • 银行汇票背书
  • 外地预缴怎么算
  • 购买的税控盘可以全额抵扣,怎么报
  • 税务局退回水利基金账务怎么处理
  • 工程施工企业外管证怎么办理
  • 个税多缴了纳税人怎么办
  • win9什么意思
  • 理解 成为 超越梗
  • win7自带xp虚拟机怎么安装驱动
  • windows刷新快捷键是什么
  • Win10 RedStone 2预览版14936快速版开始推送
  • linux应对攻击的防御手段
  • window 80端口被占用
  • win7如何彻底卸载软件
  • 怎么提升win7性能
  • win8怎么调整屏幕分辨率
  • jquery插件怎么用到自己的网站
  • css优化提高性能的方法有哪些
  • unity 3d脚本编程
  • nodejs入门教程
  • shell终端是什么意思
  • nodejs function
  • js移动dom
  • python语言的特殊符号
  • unity2d小地图
  • javascript怎么样
  • js 设计模式
  • Android alertDialog 动态添加edittext无法弹出键盘解决方案
  • 专利转让个人所得税转换为经营所得
  • 马来西亚到中国机票多少钱
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号