/*
* 正则表达式匹配
*/
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));
}
}
* 正则表达式匹配
*/
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));
}
}