位置: 编程技术 - 正文

工具类(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安卓子系统教程
  • 鸿蒙怎么添加
  • win10无法上网,显示灰色的飞行模式
  • 转账凭证摘要怎么写原材料的
  • 拍卖本人文字作品原稿
  • PHP:spl_autoload_extensions()的用法_spl函数
  • wordpress怎么搜索域名
  • 存放中央银行款项科目按其资金性质
  • 应收账款融资的风险控制
  • 分析卡拉哈迪沙漠的形成原因
  • php实现在线安装
  • 盈余公积提取和结转
  • 广告费与业务宣传费不超过当年销售收入
  • 珀斯临近什么洋
  • cvpr2020结果
  • 多线程的弊端
  • wordpress使用教程
  • 申请一般人纳税需要什么东西
  • 个体户银行开户选择哪个银行好
  • 应交增值税进项税额为什么记借方
  • sqlserver存储过程语法
  • 股权激励费用摊销意思是
  • 非营利组织也被称为?
  • 返利冲减销售收入还是进费用
  • 开劳务发票需要的资料有哪些?
  • 其他收益期末余额
  • 公司预支款应注意什么
  • 可供分配的利润是什么意思
  • 其他业务收入如何开票
  • 私人网银可以转账吗
  • 商标是无形资产还是商誉
  • 企业利润的构成内容
  • 销售免税货物的会计分录
  • 出口退税怎么回事
  • 收到货款但未开票怎么入账
  • 现金日记账月末怎么结账图片
  • 利润表的编制方法和步骤实操
  • 现金日记账怎么划线
  • MySQL数据库索引设计
  • sql server 3417错误
  • win8n
  • centos6.5设置网络
  • linux 禁用root
  • centos划分分区
  • Linux httpd(apache)启动失败 解决办法
  • 禅道界面
  • win10查看电脑配置显卡
  • WIN10安装网络打印机
  • Qt Quick + OpenGL + Bullet初次测试
  • 网络自定义怎么打开
  • wmic命令详解
  • android调用相机闪退
  • android图片库
  • python 基础 详细
  • androidstudio手机编程软件
  • JAVASCRIPT THIS详解 面向对象
  • 云南人社医保缴费步骤
  • 彩票中500万自己能得多少
  • 期初未缴税额是什么意思
  • 辽宁取暖补贴发放标准2020
  • 办公室主任和党支部书记哪个职位高
  • 武汉经济技术开发区法院立案庭电话
  • 云南省国家税务局电子税务局
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设