package org.example;
import java.text.MessageFormat;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class test2 {
public static void main(String[] args) {
String date="2019-07-13"; //给定日期
String regex="(\d{4})-(\d{1,2})-(\d{2})"; //正则匹配规定日期格式
if (date.matches(regex)){ //当匹配成功时
Matcher matcher = Pattern.compile(regex).matcher(date);
matcher.find(); //这里为空跑,只会返回一个布尔值
int year = Integer.parseInt(matcher.group(1)); //提取年月日
int month = Integer.parseInt(matcher.group(2));
int day = Integer.parseInt(matcher.group(3));
int total = day;
for (int i=1;i
如有不足,欢迎指正。



