日历创建对象: Calendar类为抽象类,不可实例化 方式一: 父类引用指向类对象 Calendar cal = new GregorianCalendar(); 方式二: Calendar cal = Calendar.getInstance(); 获取年,月,日,时,分,秒 ,毫秒 ,一年的第几天,一年的第几周,一个月的第几周,一周的第几天(周索引)月:(0-11 ) 表示1-12月 ,周索引:(1-7) 表示的周日到周六 ,周日表示1,周一时2,以此类推,周六是7 读出日历 int y
Java 8 – Date Time API Java 8 comes with a much improved and much required change in the way date and time is handled.The classes that represent the date and time concepts are present in the java.time package. The important classes in this package ar
打印new Date(),Fri Aug 12 13:37:51 CST 2016. 显示Asia/Shanghai的时区,但是date toString 的时区简写却是CST.更坑爹的是,Google CST结果出来是Central Standard Time. 表示North American Central Standard Time. 还以为jdk的date类有问题,debug date toString发现确实是将Asia/Shanghai的name 简写成CST. 接着google,
1.Date对象:Date date = getDate(); 2.Calendar实例:Calendar calendar = Calendar.getInstance(); 3.calendar.setTime(date); 4.int year = calendar.get(Calendar.YEAR); int month = calendar.get(Calendar.MONTH); int day = calendar.get(Calendar.DAY_OF_MONTH); 参考网址
用Timestamp来记录日期时间还是很方便的,但有时候显示的时候是不需要小数位后面的毫秒的,这样就需要在转换为String时重新定义格式. Timestamp转化为String: SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//定义格式,不显示毫秒 Timestamp now = new Timestamp(System.currentTimeMillis());//获取系统当前时
java.util.Date 就是在除了SQL语句的情况下面使用java.sql.Date 是针对SQL语句使用的,它只包含日期而没有时间部分它都有getTime方法返回毫秒数,自然就可以直接构建java.util.Date d = new java.util.Date(sqlDate.getTime());... --------------------------------------------------------------------------------java.util.D