1.Date中保存的是什么? 在java中,只要我们执行 Date date = new Date(); 就可以得到当前时间.如: Date date = new Date(); System.out.println(date); 输出结果是:Thu Aug 24 10:15:29 CST 2017 也就是我执行上述代码的时刻:2017年8月24日10点15分29秒.是不是Date对象里存了年月日时分秒呢?不是的,Date对象里存的只是一个long型的变量,其值为自1970年1月1日0点至Da…
一.Date类型的初始化 1. Date(int year, int month, int date); 直接写入年份是得不到正确的结果的. 因为java中Date是从1900年开始算的,所以前面的第一个参数只要填入从1900年后过了多少年就是你想要得到的年份. 月需要减1,日可以直接插入. 这种方法用的比较少,常用的是第二种方法. 2. 这种方法是将一个符合特定格式,比如yyyy-MM-dd,的字符串转化成为Date类型的数据. 首先,定义一个Date类型的对象 Date date = nul…
java中substring的使用方法 str=str.substring(int beginIndex);截取掉str从首字母起长度为beginIndex的字符串,将剩余字符串赋值给str: str=str.substring(int beginIndex,int endIndex);截取str中从beginIndex開始至endIndex结束时的字符串,并将其赋值给str; 下面是一段演示程序: public class StringDemo{ public static void main…