java 秒数减去100秒_java输入时间算秒数

展开全部

看我滴~~~~~~~~

完全按照楼主所给思路来的32313133353236313431303231363533e59b9ee7ad9431333335316537:import java.util.Scanner;

/**

* Input:

*

* Enter a date int the format yyyy/mm/dd;

*

* 1999/12/25

*

* Enter a time in the format hh:mm:ss;

*

* 11:03:25

*

* What excel date do you want it converted to? 1) Windows 2) Mac

*

* 1

*

* Output:

*

* Year: 1999 Month:12 Day:25

*

* Hour:11 Minute:3 second:25

*

* Total seconds:39805.0

*

* The Windows Excel date/time is 36519.460706018515

*

* End of Processing

*

* @author xiaobo

*

*         思路:

*

*         1.计算到目前为止的闰年数

*

*         leap=1+min(year-?,0)+【(year-?)/4】-【(year-?)/100】+【(year-?+300)/400】

*

*         其中【】表示向下取整,?表示1900或1904

*

*         2.计算该年到这个月为止的天数

*

*         d=【-1.63+(month-1)*30.6】

*

*         3.计算总的天数

*

*         result=day+(year-?)*365+leap+d

*

*/

public class CalculateSeconds {

public static void main(String []args) {

Scanner in = new Scanner(System.in);

System.out.println("Enter a date int the format yyyy/mm/dd");

String ymd = in.nextLine();

System.out.println("Enter a time in the format hh:mm:ss");

String hms = in.nextLine();

System.out

.println("What excel date do you want it converted to? 1) Windows 2) Mac");

String wm = in.nextLine();

String[] arrStr1 = ymd.split("/");

String[] arrStr2 = hms.split(":");

int year = Integer.parseInt(arrStr1[0]);

if (wm.equals("1")) {

year -= 1900;

} else if (wm.equals("0")) {

year -= 1904;

} else {

System.err.println("error");

System.exit(-1);

}

int leap = (int) (1 + Math.min(year, 0) + Math.floor(year / 4)

+ Math.floor(year / 100) + Math.floor((year + 300) / 400));

int d = (int) Math.floor(-1.63 + (Integer.parseInt(arrStr1[1]) - 1)

* 30.6);

int result = Integer.parseInt(arrStr1[2]) + year * 365 + leap + d;

System.out.println("Year:" + Integer.parseInt(arrStr1[0]) + " Month:"

+ Integer.parseInt(arrStr1[1]) + " Day:"

+ Integer.parseInt(arrStr1[2]));

System.out.println("Hour:" + Integer.parseInt(arrStr2[0]) + " Minute:"

+ Integer.parseInt(arrStr2[1]) + " second:"

+ Integer.parseInt(arrStr2[2]));

System.out.println("Total seconds:"

+ (Integer.parseInt(arrStr2[0]) * 3600

+ Integer.parseInt(arrStr2[1]) * 60 + Integer

.parseInt(arrStr2[2])));

if (wm.equals("1")) {

System.out.print("The Windows Excel date/time is ");

} else {

System.out.print("The Mac Excel date/time is ");

}

System.out.println(result + (Integer.parseInt(arrStr2[0]) * 3600

+ Integer.parseInt(arrStr2[1]) * 60 + Integer

.parseInt(arrStr2[2])) / (24 * 3600.0));

System.out.println("End of Processing");

}

}

结果如图:

3f733240e64f853f1170c7f8f21d467a.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值