博客
关于我
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/

你可能感兴趣的文章
NFS的安装以及windows/linux挂载linux网络文件系统NFS
查看>>
NFS的常用挂载参数
查看>>
NFS网络文件系统
查看>>
NFS远程目录挂载
查看>>
nft文件传输_利用remoting实现文件传输-.NET教程,远程及网络应用
查看>>
NFV商用可行新华三vBRAS方案实践验证
查看>>
ng build --aot --prod生成文件报错
查看>>
ng 指令的自定义、使用
查看>>
ng6.1 新特性:滚回到之前的位置
查看>>
nghttp3使用指南
查看>>
Nginx
查看>>
nginx + etcd 动态负载均衡实践(一)—— 组件介绍
查看>>
nginx + etcd 动态负载均衡实践(三)—— 基于nginx-upsync-module实现
查看>>
nginx + etcd 动态负载均衡实践(二)—— 组件安装
查看>>
nginx + etcd 动态负载均衡实践(四)—— 基于confd实现
查看>>
Nginx + Spring Boot 实现负载均衡
查看>>
Nginx + Tomcat + SpringBoot 部署项目
查看>>
Nginx + uWSGI + Flask + Vhost
查看>>
Nginx - Header详解
查看>>
nginx - thinkphp 如何实现url的rewrite
查看>>