Java的系统类:System、Runtime ;和时间类:Date、Calendar
2016-12-07 00:00
411 查看
1:System类的功能
2:Runtime类的功能
3:时间类 Date和Calendar
4:格式化类,格式化数字和格式化时间
格式化数字:NumberFormat类和DecimalFormat类
decimalFormat类功能比NumberFormat强大。可以定义规则
5:格式化日期simpleDateFormat类
一下几种使用方式:
将时间格式化为字符串
将字符串格式化为时间
这个主要是根据给出的字符串格式来创建SimpleDateFormat对象,然后调用parse方法即可
以上都是简单的时间格式化转换,但是平时我们会遇到很多的英文日期时间字符串,如何把他们转化为date时间对象呢?
比如:30/May/2013:17:38:25 , 这是需要借助Locale.ENGLISH。其中月份需要三个“MMM”。
获得系统的所有属性:System.getProperties() 获得系统属性中具体的属性:System.getProperty("os_name") 获得系统时间:System.currentTimeMillis() 这个时间转化为Date:new Date(System.currentTimeMillis()); 设置系统属性:System.setProperty("os_name", "window8")
2:Runtime类的功能
Runtime runtime = Runtime.getRuntime(); 启动一个进程:Runtime.getRuntime().exec("XXXX"); 获得系统空闲内存等:Runtime.getRuntime().freeMemory();
3:时间类 Date和Calendar
Java中有Date类的包有两个:java.util和java.sql,后者是前者的子类 Date类的方法很少,就是简单的获取:年、月、日以及时、分、秒还有就是获取毫秒数等。逐渐被功能 更加强大的Calendar取代 Calendar类不能用new来创建实例,而是要通过他的静态方法getInstance()方法来获得,具有比 Date更加丰富的功能方法
4:格式化类,格式化数字和格式化时间
格式化数字:NumberFormat类和DecimalFormat类
decimalFormat类功能比NumberFormat强大。可以定义规则
System.out.println(new DecimalFormat("000").format(232562)); System.out.println(new DecimalFormat("$,##0.0").format(1.2)); System.out.println(new DecimalFormat(",##0.00%").format(0.225));
5:格式化日期simpleDateFormat类
一下几种使用方式:
将时间格式化为字符串
String dateStr = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(System.currentTimeMillis()); String dateStr = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); String dateStr = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTimeInMillis()); String dateStr = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime();
将字符串格式化为时间
这个主要是根据给出的字符串格式来创建SimpleDateFormat对象,然后调用parse方法即可
Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2016-07-27 10:52:30");
以上都是简单的时间格式化转换,但是平时我们会遇到很多的英文日期时间字符串,如何把他们转化为date时间对象呢?
比如:30/May/2013:17:38:25 , 这是需要借助Locale.ENGLISH。其中月份需要三个“MMM”。
SimpleDateFormat sdf = new SimpleDateFormat("dd/MMM/yyyy:HH:mm:ss",Locale.ENGLISH); Date date = sdf.parse("30/May/2013:17:38:25");
相关文章推荐
- Java的系统类:System、Runtime ;和时间类:Date、Calendar
- 黑马程序员——Java基础——其他对象(System、Runtime、Date、Calendar、Math)
- javaseday20(系统类 时间 runtime math date calendar)
- 黑马程序员 Java基础之System,Runtime,Date,Calendar,Math.Random对象
- java--其他对象(System,Runtime,Date,Calendar,Math)
- java基础-API-System、Runtime、Date、Calendar、Math
- 黑马程序员_Java其他对象(System,Runtime,Date,Calendar,Marh-Random)
- JAVA之旅(二十三)——System,RunTime,Date,Calendar,Math的数学运算
- Java基础(其他对象System、时间类(Date、Calendar)、Math)
- 黑马程序员--Java笔记11--静态类(Collections、Arrays、System、Runtime、Date、Calendar、Math)
- 黑马程序员_JAVA- System、Runtime、Math、Date、Calendar
- 黑马程序员——Java语言基础:其他对象(System、Runtime、Date、Calendar、Math)
- JAVA-SYSTEM/RUNTIME/DATE/CALENDAR
- Java基础 System,Runtime,Date,Calendar,Math-Random,Io流
- 黑马程序员——JAVA基础之System,Runtime,Date,Calendar,Math
- Java基础之常用类--System、Runtime、Date、Calendar、Math、Random
- Java基础19--System--Runtime--Math--Date--Calendar
- java--jdk api中其他对象(System,Runtime,Calendar,Math,Random,Date)
- java--jdk api中其他对象(System,Runtime,Calendar,Math,Random,Date)
- java基础03 System,Runtime,Date,Calendar,Math