博客
关于我
Java学习笔记:日期类的使用
阅读量:813 次
发布时间:2019-03-25

本文共 653 字,大约阅读时间需要 2 分钟。

1,获取当前精确时间

使用 `new Date()` 来获取当前系统时间。

2,日期格式化

通过 SimpleDateFormat 类将 Date 实例格式化为字符串。例如:

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS");String nowTimeStr = sdf.format(nowTime);

3,获取毫秒数

使用 `System.currentTimeMillis()` 获取从1970年1月1日00:00:00到当前时间的毫秒数。以下是一个示例:

// 截取自1970年1月1日 00:00:00到当前系统的时间总毫秒数long nowTimeMillis = System.currentTimeMillis();System.out.println("当前时间总毫秒数为:" + nowTimeMillis);// 统计一个方法耗费的耗时long begin = System.currentTimeMillis();for (int i = 0; i < 1000; i++) {    System.out.println();}long end = System.currentTimeMillis();System.out.println("耗费时间为:" + (end - begin));

4,建议启动垃圾回收机制

调用 `System.gc()` 以优化内存管理和垃圾回收性能。

转载地址:http://ptjyk.baihongyu.com/

你可能感兴趣的文章
mysql csv import meets charset
查看>>
multivariate_normal TypeError: ufunc ‘add‘ output (typecode ‘O‘) could not be coerced to provided……
查看>>
MySQL DBA 数据库优化策略
查看>>
multi_index_container
查看>>
mutiplemap 总结
查看>>
MySQL Error Handling in Stored Procedures---转载
查看>>
MVC 区域功能
查看>>
MySQL FEDERATED 提示
查看>>
mysql generic安装_MySQL 5.6 Generic Binary安装与配置_MySQL
查看>>
Mysql group by
查看>>
MySQL I 有福啦,窗口函数大大提高了取数的效率!
查看>>
mysql id自动增长 初始值 Mysql重置auto_increment初始值
查看>>
MySQL in 太多过慢的 3 种解决方案
查看>>
Mysql Innodb 锁机制
查看>>
MySQL InnoDB中意向锁的作用及原理探
查看>>
MySQL InnoDB事务隔离级别与锁机制深入解析
查看>>
Mysql InnoDB存储引擎 —— 数据页
查看>>
Mysql InnoDB存储引擎中的checkpoint技术
查看>>
Mysql InnoDB存储引擎中缓冲池Buffer Pool、Redo Log、Bin Log、Undo Log、Channge Buffer
查看>>
MySQL InnoDB引擎的锁机制详解
查看>>