/*
*题目描述
输入2011年3月某一天的某一时刻,在屏幕上输出1970年1月1日至该时刻的毫秒数。
输入描述
用"-",空格及":"分隔的日期时间值。
输出描述
“毫秒数:”+整数值
输入样例
2011-03-11 15:00:00
输出样例
毫秒数:12345678
*
*
* 四年一闰;百年不闰,四百年再闰
*/
package exam1;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
*
* @author Administrator
*/
public class Test2 {
String endTime;
long haomaio;
public String getEndTime() {
return endTime;
}
public void setEndTime() throws IOException {
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
String time = br.readLine();
this.endTime = time;
}
public long getHaomaio() {
return haomaio;
}
public void setHaomaio(String endTime) {
long temp=0;
String date[] =endTime.split("[- :]");
int year=Integer.parseInt(date[0]);
int month=Integer.parseInt(date[1]);
int day=Integer.parseInt(date[2]);
int h=Integer.parseInt(date[3]);
int m=Integer.parseInt(date[4]);
int s=Integer.parseInt(date[5]);
//System.out.println(year+" "+month+" "+day+" "+h+" "+m+" "+s);
int t0=h*60*60*60+m*60*60+s*1000;
int t1=28*24*60*60*1000;
int t2=29*24*60*60*1000;
int t3=30*24*60*60*1000;
int t4=31*24*60*60*1000;
int t5=(day-1)*24*60*60*1000;
for(int i=1970;i<year;i++){
if(isRYear(i)){
temp+=366*24*60*60*1000;
}else temp+=365*24*60*60*1000;
}
if(isRYear(year)){
if(month==1){
temp+=t5+t0;
}else if(month==2){
temp+=t4+t5+t0;
}else if(month==3){
temp+=t5+t4+t2+t0;
}else if(month==4){
temp+=t5+t4*2+t2+t0;
}else if(month==5){
temp+=t5+t4*2+t3+t2+t0;
}else if(month==6){
temp+=t5+t4*3+t3+t2+t0;
}else if(month==7){
temp+=t5+t4*3+t3*2+t2+t0;
}else if(month==8){
temp+=t5+t4*4+t3*2+t2+t0;
}else if(month==9){
temp+=t5+t4*5+t3*2+t2+t0;
}else if(month==10){
temp+=t5+t4*5+t3*3+t2+t0;
}else if(month==11){
temp+=t5+t4*6+t3*3+t2+t0;
}else if(month==12){
temp+=t5+t4*6+t3*4+t2+t0;
}
}else {
if(month==1){
temp+=t5+t0;
}else if(month==2){
temp+=t4+t5+t0;
}else if(month==3){
temp+=t5+t4+t1+t0;
}else if(month==4){
temp+=t5+t4*2+t1+t0;
}else if(month==5){
temp+=t5+t4*2+t3+t1+t0;
}else if(month==6){
temp+=t5+t4*3+t3+t1+t0;
}else if(month==7){
temp+=t5+t4*3+t3*2+t1+t0;
}else if(month==8){
temp+=t5+t4*4+t3*2+t1+t0;
}else if(month==9){
temp+=t5+t4*5+t3*2+t1+t0;
}else if(month==10){
temp+=t5+t4*5+t3*3+t1+t0;
}else if(month==11){
temp+=t5+t4*6+t3*3+t1+t0;
}else if(month==12){
temp+=t5+t4*6+t3*4+t1+t0;
}
}
this.haomaio = temp;
}
public boolean isRYear(int year){
boolean isRYear=false;
if(year%4==0&&year%100!=0||year%400==0)
isRYear=true;
return isRYear;
}
public static void main(String[] args) throws IOException {
Test2 test= new Test2();
test.setEndTime();
test.setHaomaio(test.getEndTime());
System.out.println("毫秒数:"+test.getHaomaio());
}
}