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 ...
随机推荐
- git-window-install及常用命令
step 1 : msysgit安装 step 2 : 安装完毕后,打开git bash 输入以下命令: git config --global user.name xxx (用户名) git con ...
- css3 渐变色兼容移动端
.group_1 background #1a78f3 // 兼容不显示渐变色的浏览器 background: linear-gradient(180deg, #1a78f3 , #fff); bac ...
- java的BigDecimal比较大小
java的BigDecimal比较大小 //前提为a.b均不能为null if(a.compareTo(b) == -1){ System.out.println("a小于b"); ...
- MariaDB 创建表
在本章中,我们将学习如何创建表. 在创建表之前,首先确定其名称,字段名称和字段定义. 以下是表创建的一般语法: CREATE TABLE table_name (column_name column_ ...
- 编译php-5.5.15出错,xml2-config not found
今天在centos上编译php-5.5.15, cd php-5.5.15 ./configure --prefix=/usr/local/php/ --with-config-file-path=/ ...
- 【Flutter学习】之绘画实例(二)
一,画路径 - drawPath(Path path, Paint paint) Path 主要有方法如下: 直接描述路径的方法还可以细分为两组:添加子图形和画线(直线或曲线) addXXX() - ...
- 【Flutter学习】基本组件之上下刷新列表(一)
一,概述 RefreshIndicator是Flutter基于Material设计语言内置的控件,集合了下拉手势.加载指示器和刷新操作一体,可玩性比FutureBuilder差了一大截,不过大家也用过 ...
- One Switch for Mac 一键切换系统各项功能
One Switch 是火球工作室推出的最新 Mac效率软件,它在 Menubar 菜单里集成了隐藏桌面(图标).切换 Dark Mode.保持亮屏.开启屏保的一键切换按钮,将以往这些以独立小 ...
- 二进制&八进制&十六进制之间的快速转换------ 心算&笔算方法总结
二进制数 0&1两种元素: 8进制数 0-7 八种元素: 十六进制数 0-9,a,b,c,d,e, ...
- jquery实现简单的搜索功能
管理系统中需要实现导航列表的搜索功能,写了一个简单的小栗子: <!DOCTYPE html> <html lang="en"> <head> & ...