博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
new Date() vs Calendar.getInstance().getTime()
阅读量:5086 次
发布时间:2019-06-13

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

System.currentTimeMillis()

vs.

new Date()

vs.

Calendar.getInstance().getTime()

System.currentTimeMillis() is obviously the most efficient since it does not even create an object, but new Date() is really just a thin wrapper about a long, so it is not far behind. Calendar, on the other hand, is relatively slow and very complex, since it has to deal with the considerably complexity and all the oddities that are inherent to dates and times (leap years, daylight savings, timezones, etc.).

It's generally a good idea to deal only with long timestamps or Date objects within your application, and only use Calendar when you actually need to perform date/time calculations, or to format dates for displaying them to the user. If you have to do a lot of this, using  is probably a good idea, for the cleaner interface and better performance.

转载于:https://www.cnblogs.com/kakaisgood/p/11165057.html

你可能感兴趣的文章
开源的截图工具
查看>>
Eclipse4.7安装SWT
查看>>
POJ 1840 Eqs(哈希表)
查看>>
算法题目
查看>>
20170728 Celery项目 后台处理SQL SERVER的一个异常
查看>>
20180318 一个VS2015运行DataTable问题
查看>>
SSM框架整合
查看>>
PAT 1001-1010 题解
查看>>
创龙TMS320C6748开发板串口和中断学习笔记
查看>>
01 C语言程序设计--01 C语言基础--第3章 基本数据类型01
查看>>
Java 反射机制详解(上)
查看>>
oracle drop table(表)数据恢复方法
查看>>
编译LAMP部署动态网站环境
查看>>
Java 8 新的时间日期 API
查看>>
PHP基本语法
查看>>
Linux命令应用大词典-第8章 日期和时间
查看>>
jenkins+maven+svn构建项目,及远程部署war包到tomcat上
查看>>
图解CSS3之弹性盒模型篇(display:box / display:inline-box)
查看>>
【iOS】UIImageView 点击事件
查看>>
自动跟踪足球场上所有的选手
查看>>