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()的更多相关文章

  1. 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 ...

  2. java成神之——date和calendar日期的用法

    date和calendar日期的用法 util的data转换成sql的data 创建Date对象 格式化 Instant ChronoUnit LocalTime LocalDate LocalDat ...

  3. Java 时间类 Date 和 Calendar

    在项目中获取一个yyyy-MM-dd HH:mm:ss格式的时间字符串 package org.htsg.kits; import java.text.SimpleDateFormat; import ...

  4. java中Calendar.getInstance()和new Date()的差别是什么?

    java中Calendar.getInstance()和new Date()的差别如下: Calendar.getInstance()是获取一个Calendar对象并可以进行时间的计算,时区的指定ne ...

  5. Date和Calendar时间操作常用方法及示例

    package test; import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.Date; /** ...

  6. Java日期与时间的处理/Date,String,Calendar转换

    public class Demo01 { //Java中Date类和Calendar简介 public static void main(String[] args) { long now=Syst ...

  7. java日期类型转换总结date timestamp calendar string

    用Timestamp来记录日期时间还是很方便的,但有时候显示的时候是不需要小数位后面的毫秒的,这样就需要在转换为String时重新定义格式.         Timestamp转化为String: S ...

  8. Java:Date、Calendar、Timestamp的使用

    一.Java.util.Date 该对象包含了年月日时分秒信息.具体使用如下代码: //String 转换为Date private static void dateDemo() throws Par ...

  9. Java:Date、Calendar、Timestamp的区别、相互转换与使用【转载】

    1 Java.util.Date 包含年.月.日.时.分.秒信息 包含年.月.日信息. 继承自java.util.Date.在数据库相关操作中使用,如rs.getDate,ps.setDate等.rs ...

随机推荐

  1. 用java 调用oracle存储过程总结

    SSM-Mybatis调用Oracle存储过程返回结果集(游标)示例 https://www.jianshu.com/p/0ae6d9d66d61 用java调用oracle存储过程总结 //1.ca ...

  2. 2018-2-13-win10-UWP-你写我读

    title author date CreateTime categories win10 UWP 你写我读 lindexi 2018-2-13 17:23:3 +0800 2018-2-13 17: ...

  3. Mysql学习笔记(003)-案例讲解基础查询

    案例讲解基础查询 #.下面的语句是否可以执行成功 SELECT last_name, first_name, salary AS sal FROM employees; #.下面的语句是否可以执行成功 ...

  4. 页面重置样式reset.css

    我把经常用到的一些页面重置样式归类到了一个.css文件中,这样可以减少代码冗余.当然还有其他的很多用处,比如h1~h5的样式全部统一的话,下面写东西很清晰很多. @charset 'utf-8'; h ...

  5. SQL注入系列:SQLi Labs

    前言 关于注释 说明:在SQL中--[空格]表示注释,但是在URL中--空格在发送请求的时候会把最后的空格去掉,所以用--+代替,因为+在被URL编码后会变成空格 MYSQL有三种常用注释: --[空 ...

  6. layer icon对应图标

    layer icon对应图标 信息框(msg.alert.open.confirm) icon:0 icon:1 icon:2 icon:3 icon:4 icon:5 icon:6 icon:16 ...

  7. CSS 的基础语法

    1.基础语法规则 CSS 规则由两个主要的部分构成:选择器,以及一条或多条声明. 每条声明由一个属性和一个值组成.每个属性有一个值.属性和值被冒号分开. selector {property: val ...

  8. Postgresql临时表

    PostgreSQL支持两类临时表,会话级和事务级临时表.在会话级别的临时表中,在整个会话的生命周期中,数据一直保存.事务级临时表,数据只存在于这个事务的生命周期中.不指定临时表的属性, Postgr ...

  9. Java BIO socket

    package org.rx.socks; import lombok.extern.slf4j.Slf4j; import org.rx.core.LogWriter; import org.rx. ...

  10. CompletableFuture提高你并发编程能力

    思考:如果有两个顺序执行耗时的方法,你该怎么做??? 例如: public void doHousework() { //烧水 doWater(); //扫地 doFloor(); } 没错,聪明如我 ...