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. 【教程】linux安装nginx(详细)

    博主最近在安装Nginx,虽然之前安装过,但是没有记录安装过程,导致现在安装过程中遇到坑,现记录一下,希望能帮助到你. 1:安装编译工具及库文件 yum -y install make zlib zl ...

  2. eclipse导入了jar查看不了源码解决方法

    当导入源码的时候ctrl+左键的时候,还是查看不了源码.问题一直困扰我很久,百度了很多方法.现在分享下解决的方法. 经过简单整理,如下: 第一步:下载JAD . jad官方地址的官方下载地址是: ht ...

  3. dotNET面试(一)

    1.列举ASP.NET 页面之间传递值的几种方式. 1).使用QueryString, 如....?id=1; response. Redirect().... 2).使用Session变量 3).使 ...

  4. Android开发中怎样用多进程、用多进程的好处、多进程的缺陷、解决方法(转)

    转自:http://blog.csdn.net/spencer_hale/article/details/54968092 1.怎样用多进程 Android多进程概念:一般情况下,一个应用程序就是一个 ...

  5. svn解决方案

    1.svn回退 revert to this version 2.不同svn路径拉倒一个本地文件夹,报错"已经指向不同的url工作副本":  删除文件夹中的.svn文件夹 3.sv ...

  6. CH340电路设计

    版权声明:技术需要共享,但同时需要尊重原创者的辛劳,转载引用请注明出处. https://blog.csdn.net/JAZZSOLDIER/article/details/66967735 最近选用 ...

  7. js消除图片小游戏

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. iview select下拉框的蜜汁小坑

    前言 最近使用iview的select下拉选择器,遇到一个很神奇的问题:选中下拉框里面的一个值,但是再去点下拉框的时候就只剩刚才选中的数据了.感觉应该是插件把刚才选中的数据当做的搜索条件,所以需要做的 ...

  9. 搭建ELK和EFK

    公司突然发下任务让我搭建elk和efk,于是做完之后写入了博客,生产环境下,亲测可用哦 搭建ELK 一共两台服务器,一个节点(logstash) 主服务器上 修改最大链接和最大打开的文件 1.临时修改 ...

  10. 【JS】js引擎执行过程

    概述 js引擎执行过程主要分为三个阶段,分别是语法分析,预编译和执行阶段,上篇文章我们介绍了语法分析和预编译阶段,那么我们先做个简单概括,如下: 语法分析: 分别对加载完成的代码块进行语法检验,语法正 ...