黑马程序员技术交流社区

标题: 统计字符串中的年月日 [打印本页]

作者: 穆帆    时间: 2015-10-2 12:07
标题: 统计字符串中的年月日
public class Demo {
        public static void main(String[] args) {
                String str = "2015-09-11";
                //取出这个字符中的年月日信息
                String year = str.substring(0,str.indexOf("-"));//年
               
                int index = str.indexOf("-");
                int start = index + 1;
        //        int end = str.lastIndexOf("-");
                int end = str.indexOf("-",start);
                String month = str.substring(start,end);//月
                String day = str.substring(str.lastIndexOf("-") + 1);//日
                System.out.println(year + "," + month + "," + day);
               
               
               
        }
}






欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2