美文网首页
如何从时间字符串中获取单独的年月日

如何从时间字符串中获取单独的年月日

作者: 栏土豆 | 来源:发表于2019-06-25 09:22 被阅读0次

Pattern p=Pattern.compile("(\\d{4})-(\\d{1,2})-(\\d{1,2})");//从时间字符串中获取年,月,日的正则表达式

if (StringUtils.isBlank(StrTime)) {

      Matcher m=p.matcher(endTime);

    if(m.find()){

        System.out.println("日期:"+m.group());

        System.out.println("年:"+m.group(1));

        System.out.println("月:"+m.group(2));

        System.out.println("日:"+m.group(3));

    }

}

相关文章

网友评论

      本文标题:如何从时间字符串中获取单独的年月日

      本文链接:https://www.haomeiwen.com/subject/otbzqctx.html