位置: 编程技术 - 正文

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

  • 小规模纳税人500万以内免税
  • 借款发生的利息费用
  • 营业账簿指什么
  • 汇算清缴可以调成本吗
  • 必胜客发票提取码在小票哪里
  • 废旧物资回收经营范围
  • 计算土地增值税时增值税可以扣除吗
  • 购买的发票进项税和成本怎么转出
  • 测绘费能否在土地出让
  • 一般账户网银可以发工资吗
  • 火车车票怎么样
  • 怎么确认收到的钱是哪个项目的
  • 企业所得税汇算交所得税如何做账务处理
  • 营改增后房屋租赁如何纳税
  • 用现金发工资不给怎么办
  • 注册资本转让股权
  • 企业支付在哪里
  • 免税行业企业
  • 正常工资薪金本期收入含哪些
  • 购车发票怎么做分录
  • 减免教育费附加和地方教育费附加账务处理
  • 如何申请残疾人
  • 电子承兑汇票贴现怎么做账
  • 收到生育津贴的短信是真的吗
  • 收货款时少收几十元,分录怎么做
  • 炫龙dd3笔记本怎么样
  • deepin怎么退出命令行
  • 临时工工资应该找人力资源要吗
  • arm on windows
  • 栗耳簇舌巨嘴鸟,巴西潘塔纳尔保护区里 (© Ana Gram/Shutterstock)
  • 忘记电脑开机密码怎么打开电脑
  • windows 11什么时候
  • php string
  • 小规模纳税人销售商品会计分录
  • php lee
  • 出售固定资产减按2%会计处理1%怎么处理
  • 不动产经营租赁包括哪些内容
  • 进项发票认证操作
  • php session_id
  • php -i
  • 珠穆朗玛峰的壮观
  • 中小企业所得税优惠政策2022
  • 一篇文章让你了解什么
  • 03-JavaScript基础
  • 哪些服务可以开具经纪代理服务发票
  • 资产账面价值大于计税基础产生递延所得税负债
  • 什么情况下可以转入资本公积
  • 增值税主要内容
  • 增值税专票三联都丢了写情况说明可以吗
  • mongodb 入门
  • 三代手续费操作流程
  • 政府会计的会计要素有哪几个?会计要素之间的关系如何?
  • 法人转让股权,可以打个人账户吗
  • 预交增值税后期处理
  • 社保缴纳的时候可以用吗
  • 个人收到国外汇款后怎么办
  • 营业外支出包括
  • 苗木种植发票免税怎么开
  • 如何定义是应付还是应付
  • 抵扣联和发票联的区别
  • 合同资产百度百科
  • 完全成本法作业成本法变动成本法对企业的影响
  • 免费领课程有什么陷阱
  • Linux环境下MySQL服务器优化的方法详解
  • win7系统调亮度怎么调
  • ubuntu16.04输入法
  • ssd固态硬盘内部结构图
  • 快速解决便秘的小妙招
  • 利用python进行
  • 如何使用maven
  • python djang
  • opengl es3.0
  • node性能优化
  • jquery动态设置css
  • Android spinner 的使用
  • bootstrap需要学多久
  • 国家税务总局令第43号公告
  • 保险的佣金一般是多少
  • 深圳市税务审批中心电话
  • 如何在个税app中设置企业登录密码
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设