學(xué)習(xí)小結(jié)
15.4.2 日期格式化類
java.time.format專門格式化日期時(shí)間的。
范例 15-11 將時(shí)間對象格式化為字符串
package com.Javastudy2;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
/**
* @author Y.W.
* @date 2018年5月15日 下午11:08:55
* @Description TODO 將時(shí)間對象格式化為字符串
*/
public class P396_15_11 {
public static void main(String[] args) {
// 獲取當(dāng)前時(shí)間
LocalDate localDate = LocalDate.now();
// 指定格式化規(guī)則
DateTimeFormatter f = DateTimeFormatter.ofPattern("dd/MM/uuuu");
// 將當(dāng)前時(shí)間格式化
String str = localDate.format(f);
System.out.println("時(shí)間:" + str);
}
}
運(yùn)行結(jié)果:
運(yùn)行結(jié)果
15.5 正則表達(dá)式
15.5.1 正則的引出
范例 15-12 判斷字符串是否由數(shù)字組成
package com.Javastudy2;
/**
* @author Y.W.
* @date 2018年5月15日 下午11:21:21
* @Description TODO 判斷字符串是否由數(shù)字組成
*/
public class P397_15_12 {
public static void main(String[] args) {
if (isNumber("123")) { // 判斷字符串是否有數(shù)字組成
System.out.println("由數(shù)字組成命咐!");
} else {
System.out.println("不是由數(shù)字組成裁赠!");
}
}
public static boolean isNumber(String str){
char data[] =str.toCharArray(); // 將字符串轉(zhuǎn)換為char數(shù)組
for (int i = 0; i < data.length; i++) { // 循環(huán)遍歷該數(shù)組
if(data[i]<'0'||data[i]>'9'){ // 判斷數(shù)組中的每個(gè)元素是否是數(shù)字
return false;
}
}
return true;
}
}
運(yùn)行結(jié)果:
運(yùn)行結(jié)果
思考
開始正則表達(dá)式植兰,有點(diǎn)小激動(dòng)纽甘。
記于2018-5-15 23:33:19
By Yvan