java正则匹配实现字符串2014-9-10 22:34 对应加上n秒后的时间

/*
 * 正则表达式匹配
 */
package StringRegex;


import java.util.regex.Matcher;
import java.util.regex.Pattern;




public class TimePuls {
public static void main(String[]  args){
String s1 = new String("2014-09-24  17:26:23");
String s2 = new String();
int n = 100000;
s2 = timePuls(s1,n);
System.out.println(s2);
}

private static String timePuls(String s2, int n) {
Pattern p = Pattern.compile("(\\d{4})(\\-)(\\d{2})(\\-)(\\d{2})(\\s+)(\\d{2})(\\:)(\\d{2})(\\:)(\\d{2})");
Matcher m = p.matcher(s2);
StringBuffer buf = new StringBuffer();
String zjz = new String();
int nr=0,y=0,r=0,s=0,f=0,ma=0;
while(m.find()){
nr=Integer.parseInt(m.group(1));
y=Integer.parseInt(m.group(3));
r=Integer.parseInt(m.group(5));
s=Integer.parseInt(m.group(7));
f=Integer.parseInt(m.group(9));
ma=Integer.parseInt(m.group(11));
}
while(0!=n){
ma++;
n--;
if(ma>=60){
ma=0;
f++;
if(f>=60){
f=0;
s++;
if(s>=12){
s=0;
r++;
if(r>=31){
r=1;
y++;
if(y>=13){
y=1;
nr++;
}

}
}
}

}

}



return (new String(nr + "-" + y + "-" + r + "  " + s + ":" + f + ":" +ma));
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值