学习小结
15.4.2 日期格式化类
java.time.format专门格式化日期时间的。
范例 15-11 将时间对象格式化为字符串
package com.Javastudy2;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
/**
* @author Y.W.
* @date 2018年5月15日 下午11:08:55
* @Description TODO 将时间对象格式化为字符串
*/
public class P396_15_11 {
public static void main(String[] args) {
// 获取当前时间
LocalDate localDate = LocalDate.now();
// 指定格式化规则
DateTimeFormatter f = DateTimeFormatter.ofPattern("dd/MM/uuuu");
// 将当前时间格式化
String str = localDate.format(f);
System.out.println("时间:" + str);
}
}
运行结果:

运行结果
15.5 正则表达式
15.5.1 正则的引出
范例 15-12 判断字符串是否由数字组成
package com.Javastudy2;
/**
* @author Y.W.
* @date 2018年5月15日 下午11:21:21
* @Description TODO 判断字符串是否由数字组成
*/
public class P397_15_12 {
public static void main(String[] args) {
if (isNumber("123")) { // 判断字符串是否有数字组成
System.out.println("由数字组成!");
} else {
System.out.println("不是由数字组成!");
}
}
public static boolean isNumber(String str){
char data[] =str.toCharArray(); // 将字符串转换为char数组
for (int i = 0; i < data.length; i++) { // 循环遍历该数组
if(data[i]<'0'||data[i]>'9'){ // 判断数组中的每个元素是否是数字
return false;
}
}
return true;
}
}
运行结果:

运行结果
思考
开始正则表达式,有点小激动。
记于2018-5-15 23:33:19
By Yvan