位置: 编程技术 - 正文

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

  • 应税消费品是什么意思
  • 口罩属于什么经营类别
  • 年终销项税额要结账吗
  • 已付款收不到发票怎么办
  • 取得租金收入的会计分录
  • 税前可以扣除的有哪些费用
  • 资本公积金转增股本所获取的收益属于
  • 税收返还怎么做会计分录
  • 农产品收购发票是普票还是专票
  • 固定资产的清查由哪个部门负责
  • 营改增阶段
  • 逃避缴纳税款罪移送公安标准
  • 资本公积转增资本会引起什么变化
  • 员工因公负伤期间公司怎么开工资
  • 节能控制模块
  • 营改增后的税率
  • 固定资产清理税金如何处理
  • win11怎么关闭进程
  • 新会计准则的科目
  • 交契税需要什么东西
  • php 字符串 数组
  • php可以和iis配合运行吗?
  • 出租不动产增值税纳税义务发生时间
  • 退伍兵自谋职业后被单位辞退怎么办
  • 网络分割算法
  • ubuntu20.04安装opencv3.4
  • 程序人是什么意思
  • 包装费包含什么
  • 刚成立的新公司怎么报税
  • 分页浏览是什么意思
  • 增值税附加税减免政策2022年
  • 未开票要交增值税吗
  • mongodb视频教程
  • 外经证是啥样
  • 用于职工福利的固定资产折旧
  • 自然人独资的有限责任公司交什么税
  • 购买办公用品如何写摘要
  • 未开票收入是怎么算的
  • 个人所得税和投保的区别
  • sql server操作教程
  • 小规模纳税人工程款税率是多少
  • 以前年度损益调整科目编码是多少
  • 租赁房产税计税依据及计算方式是什么
  • 销售自产农产品的农民是增值税纳税人吗
  • 暂估入账错误了怎么办
  • 股权转让印花税减半征收政策
  • 母公司代发子公司工资,子公司申报个税
  • 汽车折旧年限及残值率是多少
  • 建筑企业其他应付款包含什么内容
  • 年度汇算清缴要补税怎么办
  • 空档期太长是不是很难找工作
  • 员工报销没有发票可以从公户转账吗
  • 汽车折旧计算方法2023折旧率
  • 账户记录试算不平衡说明记账肯定有差错对吗
  • sqlserver使用方法
  • win7用u盘怎么重装系统
  • xp电脑搜索文件为什么搜索不出来
  • linux中man的用法
  • 电脑自建热点
  • 重装系统后win7无法连接到网络
  • win7系统开启无线服务
  • win10家庭版关闭
  • win7怎么设置u盘启动为第一启动项
  • 用360可以装win7系统吗
  • unity怎么bake
  • Android Broadcast
  • cocos2dx 不规则按钮的实现
  • textview在哪
  • 非递归与递归
  • javascript数学函数
  • 基于vue的ui框架
  • unity study
  • 税务核销
  • 江西省电子税务局公众查询
  • 中国税务是做什么的
  • 农村饮水扶持资金申请报告
  • 购电脑折旧的会计分录
  • 首问责任制的概念
  • 营业税属于地方税
  • 怎么修改纳税人信息
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设