CommonUtils(一)
来源:互联网 发布:c语言void的应用 编辑:程序博客网 时间:2024/06/06 14:01
1、 时间转换类
//a: 将日期格式转换为13位private long convertDate2Long(String str) { java.text.SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-hh HH:mm:ss"); long date = 0L; try { Date d = format.parsr(str); //时间格式必须一致,否则会提示错误 date = d.getTime(); //如果为10位,则d.getTime() / 1000L }catch(Exception e) { throw new RuntimeException("***"); } return date;}//b: 将13位转换为日期格式private String convertTimeToString(long longTime, String format) { //format: "yyyy-MM-dd HH:mm:ss" java.sql.Timestamp ts; try { ts = new Timestamp(longTime); //如果是10位,此处longTime * 1000L SimpleDateFormat s = new SimpleDateFormat(format); return s.format(t); } catch(Exception e) { throw new :::; }}
2、 创建文件唯一名称
String uuid = UUID.randomUUID().toString();
3、二进制、八进制、十进制、十六进制转换
public static void main(String[] args) { // 不管是哪种进制的数据赋值, 在计算机中都是二进制, 所以i和j在计算机中存储方式是一样的 int i = 0xff; System.out.println("Hex = " + Integer.toHexString(i)); System.out.println("Octal = " + Integer.toOctalString(i)); System.out.println("Binary = " + Integer.toBinaryString(i)); System.out.println("Decimal = " + i); int j = 0377; System.out.println("Hex = " + Integer.toHexString(j)); System.out.println("Octal = " + Integer.toOctalString(j)); System.out.println("Binary = " + Integer.toBinaryString(j)); System.out.println("Decimal = " + j);}//以下是程序运行结果Hex = ffOctal = 377Binary = 11111111;Decimal = 255Hex = ffOctal = 377Binary = 11111111;Decimal = 255
阅读全文
0 0
- CommonUtils(一)
- CommonUtils
- 配置一些项目中用到的小工具(一)----------CommonUtils
- CommonUtils.toBean和CommonUtils.uuid
- Java 工具类--CommonUtils
- commonUtils简单总结
- java小工具CommonUtils
- CommonUtils 工具类
- CommonUtils的工具类
- 1、CommonUtils.uuid()和CommonUtils.toBean(map, Person.class)
- 小工具(1):项目所需小工具之CommonUtils(1生成uuid,2Map转换成JavaBean)
- 一些帮助类:CommonUtils,,,,OkHttp3Util
- 浅谈Java工具类CommonUtils的使用
- CommonUtils中的工具UUID和ToBean
- 项目实践积累我的工具类——CommonUtils
- 1-JavaScript设计模式——commonUtils工具库之多维数组的遍历
- 2-JavaScript设计模式——commonUtils工具库之继承函数
- 3-JavaScript设计模式——commonUtils工具库之接口类
- Boost库高效内存管理——smart_ptr库——scoped_ptr/scoped_array
- 单片机的架构介绍
- qt5显示中文乱码
- HTML5&CSS3常用属性和方法
- liunx系统(centos)如何关闭指定端口
- CommonUtils(一)
- 进制转换基础
- 各种开源汇编、反汇编引擎的非专业比较
- 使用Genymotion模拟器模拟平板设备
- [UOJ 220]网格:Tarjan
- mysql添加新的一列作为主键以及修改列
- java学习笔记2类和对象
- 第一篇博客-自己的几点感想
- 微信抢红包插件与Android辅助功能