new Date() vs Calendar.getInstance().getTime()
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 Joda Time is probably a good idea, for the cleaner interface and better performance.
new Date() vs Calendar.getInstance().getTime()的更多相关文章
- java基础1.5版后新特性 自动装箱拆箱 Date SimpleDateFormat Calendar.getInstance()获得一个日历对象 抽象不要生成对象 get set add System.arrayCopy()用于集合等的扩容
8种基本数据类型的8种包装类 byte Byte short Short int Integer long Long float Float double Double char Character ...
- java成神之——date和calendar日期的用法
date和calendar日期的用法 util的data转换成sql的data 创建Date对象 格式化 Instant ChronoUnit LocalTime LocalDate LocalDat ...
- Java 时间类 Date 和 Calendar
在项目中获取一个yyyy-MM-dd HH:mm:ss格式的时间字符串 package org.htsg.kits; import java.text.SimpleDateFormat; import ...
- java中Calendar.getInstance()和new Date()的差别是什么?
java中Calendar.getInstance()和new Date()的差别如下: Calendar.getInstance()是获取一个Calendar对象并可以进行时间的计算,时区的指定ne ...
- Date和Calendar时间操作常用方法及示例
package test; import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.Date; /** ...
- Java日期与时间的处理/Date,String,Calendar转换
public class Demo01 { //Java中Date类和Calendar简介 public static void main(String[] args) { long now=Syst ...
- java日期类型转换总结date timestamp calendar string
用Timestamp来记录日期时间还是很方便的,但有时候显示的时候是不需要小数位后面的毫秒的,这样就需要在转换为String时重新定义格式. Timestamp转化为String: S ...
- Java:Date、Calendar、Timestamp的使用
一.Java.util.Date 该对象包含了年月日时分秒信息.具体使用如下代码: //String 转换为Date private static void dateDemo() throws Par ...
- Java:Date、Calendar、Timestamp的区别、相互转换与使用【转载】
1 Java.util.Date 包含年.月.日.时.分.秒信息 包含年.月.日信息. 继承自java.util.Date.在数据库相关操作中使用,如rs.getDate,ps.setDate等.rs ...
随机推荐
- 在linux中出现there are stopped jobs 的解决方法【转自:http://www.linuxdiyf.com/viewarticle.php?id=104604】
在用管理员执行一个命令后,我用Ctrl+Z把命令转移到了后台天.导致我无法退出root的. 输入命令:logout终端显示:There are stopped jobs. 解决方法:输入命令:jobs ...
- Rxjava Retrofix2 okhttp3网络框架自解(转)
直接代码 类一 public class Okhttp3Utils { private static OkHttpClient mOkHttpClient; public static OkHttpC ...
- 12.Unsafe原子性操作
import sun.misc.Unsafe; /** * JDK8 * JDK 的此jar 包中的 Unsafe 类提供了硬件级别的原子性操作 */ public class UnsafeTest ...
- C#中using语句是什么意思
使用using语句最终生成的其实是一个try, finally代码块,在finally代码块里释放资源.要求是:为 using 语句提供的对象必须实现 IDisposable 接口.此接口提供了 Di ...
- iOS项目开发中的知识点与问题收集整理②
1.点击UIButton 无法产生触摸事件 如果在UIImageView中添加了一个按钮,你会发现在默认情况下这个按钮是无法被点击的,需要设置UIImageView的userInteractio ...
- Docker 镜像添加模块
Docker 镜像添加模块 1. 使用root用户进入一个新容器,不要用 --rm .否则退出容器的时候,容器没有了 docker run --user 0 -it --name superman ...
- shell 输入输出重定向
1. 命令列表: command > file 将输出重定向到file command < file 将输入重定向到file command >> file 将输出以追加的方式 ...
- 极简Vue的异步组件函数
export default new Router({ routes: [ { path: '/live', name: 'live', component: () => import('@/v ...
- PHP面试 MySQL创建高性能索引考点
MySQL索引 MySQL索引的基础和类型 索引的基础:索引类似于书籍的目录,要想找到一本书的某个特定篇章,需要查找书的目录,定位对应的页码 存储引擎使用类似的方式进行数据查询,先去索引当中找到对应的 ...
- python模块学习之testlink (自动回写测试案例执行结果到testlink)
安装 pip install TestLink-API-Python-client #!/usr/bin/env Python # -*- coding: utf-8 -*- ''' Created ...