1. System.currentTimeMillis()

vs.

  1. new Date()

vs.

  1. 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. 用html标签+css写出旋转的正方体

    有一段时间没写代码了,刚写有点手生,无从下手,为了能快速进入状态,就写了这一个小东西,纯用标签和样式表写.下面看一下我写的. 这一段是样式表: <style> *{ margin: 0; ...

  2. WPFのStyle TargetType的不同写法

    一.隐式写法 <Style TargetType="TextBlock"> <Setter Property="/> </Style> ...

  3. websocket(python)

    1.websocket-server https://github.com/google/pywebsocket git clone https://github.com/google/pywebso ...

  4. 【记录】linux 命令拷贝文件到远程服务器,linux下载文件到本地

    Linux scp命令用于Linux之间复制文件和目录 -1 强制scp命令使用协议ssh1 -2 强制scp命令使用协议ssh2 -4 强制scp命令只使用IPv4寻址 -6 强制scp命令只使用I ...

  5. 交叉编译fw_printenv

    source /opt/poky/environment... 创建交叉编译环境. 更改u-boot/tools/env/Make 添加CC 9 CC=aarch64-poky-linux-gcc - ...

  6. 如何用Word制作斜线表头?

    如何用Word制作斜线表头?遇到这种问题,你一般是如何操作?本期企业网盘坚果云干货分享与大家分享有关斜线表头的制作方法. 斜线表头分单斜线表头和多斜线表头,下面分情况来了解相关的解决办法. 单斜线表头 ...

  7. filter 过滤emoji

    拦截器 public class EmojiFilter implements Filter { private FilterConfig filterConfig; public void init ...

  8. 数据结构---Java---String、StringBuilder、StringBuffer

    1.概述 1.1 String:不可变字符串 public final class String implements java.io.Serializable, Comparable<Stri ...

  9. Java实现按汉语拼音的排序

    public class sortByPinyin { public static void main(String[] args) { String[] arr = { "刘刘" ...

  10. BZOJ 3569: DZY Loves Chinese II(线性基)

    传送门 解题思路 首先构造出一个生成树,考虑不连接的情况.假设连通两点的非树边和树边都断掉后不连通,那么可以给所有的非树边随机一个互不相同的值,然后树边的权值为过他两端点的非树边权值的异或和,这个可以 ...