常用类:
什么是常用类,也可以说是在我们开发中的一些常用的一些工具类
常用的类有以下的一些,标*的是重点:
—时间
java.util.Date *
Java.util.Locale
Java.util.Calendar *
Java.text.DateFormat
Java.text.SimpleDateFormat *
—系统
Java.lang.System
Java.lang.Runtime
—数学 随机数
Java.lang.Math
Java.util.Random *
—字符串
Java.lang.String *
Java.lang.StringBuffer *
Java.lang.StringBuilder
—数组
Java.util.Arrays *
—机器人
Java.awt.Robot
java.util.Date 的写法如下:
![image](http://os78f4hny.bkt.clouddn.com/20170710016.jpg)
long time = System.currentTimeMillis();
System.out.println(System.currenTimeMillis()-time)
Date date1 = new Date(System.currentTillis());
Date date2 = new Date();
System.out.println(date2.getYear() + 1900);
System.out.println(date2.getMonth() + 1);
System.out.println(date2.getDate());
System.out.println(date2.getHours());
System.out.println(date2.getMinutes());
System.out.println(date2.getSeconds());
Date date3 = new Date(117,6,7,7,7,7);
System.out.println(date3.getTime);
Date date = new Date();
System.out.println(date.toString());
Locale.setDefault(Locale.US);
![image](http://os78f4hny.bkt.clouddn.com/20170710017.jpg)
System.out.println(date.toLocaleString());
System.out.println(date.getTime);
Java.util.Calendar 日历类的写法:
什么是日历类,就是可以对时间的增加,减少,还可以做到星期的获得,就是做时间的运算
Calendar calendar = Calendar.getInstance();
Calendar.setTime(new Date(117,7,7,7,7,7));
System.out.println(calendar.get(Calendar.YEAR));
System.out.println(calendar.get(Calendar.MONTH)+1);
System.out.println(calendar.get(Calendar.DATE));
System.out.println(calendar.get(Calendar.HOUR_OF_DAY));
System.out.println(calendar.get(Calendar.MINUTE));
System.out.println(calendar.get(Calendar.SECOND));
![image](http://os78f4hny.bkt.clouddn.com/20170710018.jpg)
System.out.println(calendar.get(Calecdar.MILLISECOND));
System.out.println(calendar.get(Calendar.DAY_OF_YEAR));
System.out.println(calendar.get(Calendar.DAY_OF_MONTH));
System.out.println(calendar.getActualMaximum(Calendar.DATE));
calendar .set(Calendar.MONTH,5-1);
calendar .add(Calendar.DATE,150);
System.out.println(calendar.getTime().tiLocaleString());
|