java编写一个简单的输入生日计算下一个生日时间的代码?

java编写一个简单的输入生日计算下一个生日时间的代码?,第1张

import java.util.Calendar

import java.util.Scanner

import java.util.concurrent.TimeUnit

/**

* Title: Test03.java<br>

* Description:

*

* @author 王凯芳

* @date 2020年3月5日世启 下午6:03:04

* @version 1.0

*

* @request 编写一个方法能计算任何一个人今天离他最近下一次生日还有多少天,然后在主方法(main方法)中输入你的出生年月日,调用该方法的计算结果并输出信息“某某同学离自己最近下一次生日x天谨返销”。

*/

public class Test03 {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in)

System.out.println("祥游请输入你的姓名:")

String name = sc.nextLine()

System.out.println("请输入你的生日,格式为(2000/01/01):")

String line = sc.nextLine()

String[] strs = line.split("/")

if (strs.length == 3) {

int days = getDays(strs[0], strs[1], strs[2])

if (days == 0) {

System.out.println(String.format("%s 同学,今天是你的生日,祝你生日快乐(#^.^#)", name, days))

} else {

System.out.println(String.format("%s 同学离自己最近下一次生日%d天。", name, days))

}

} else {

System.out.println("生日输入不正确!请按格式输入。")

}

sc.close()

}

/**

* 获取最近一次生日天数

*

* @param year

* @param month

* @param day

* @return

*/

public static int getDays(String year, String month, String day) {

Calendar now = Calendar.getInstance()

now.set(Calendar.HOUR_OF_DAY, 0)

now.set(Calendar.MINUTE, 0)

now.set(Calendar.SECOND, 0)

now.set(Calendar.MILLISECOND, 0)

int now_year = now.get(Calendar.YEAR)

Calendar birthday = Calendar.getInstance()

birthday.set(Calendar.YEAR, now_year)

birthday.set(Calendar.MONTH, Integer.parseInt(month) - 1)

birthday.set(Calendar.DAY_OF_MONTH, Integer.parseInt(day))

birthday.set(Calendar.HOUR_OF_DAY, 0)

birthday.set(Calendar.MINUTE, 0)

birthday.set(Calendar.SECOND, 0)

birthday.set(Calendar.MILLISECOND, 0)

long diff = now.getTimeInMillis() - birthday.getTimeInMillis()

if (diff == 0) {

return 0

} else if (diff <0) {

long diffDays = TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS)

return Math.abs((int) diffDays)

} else {

birthday.add(Calendar.YEAR, 1)

long diffMi = birthday.getTimeInMillis() - now.getTimeInMillis()

long diffDays = TimeUnit.DAYS.convert(diffMi, TimeUnit.MILLISECONDS)

return (int) diffDays

}

}

}

用java写的话 要做得很好 已经来不及了

我建议你用ZineMaker 2006做一个杂志 可以做得很漂亮 可以加她照片、背景音乐加特殊效果等等 她看见了肯定会感动的

这里一个常见的 也给你

<html>

<head>

<title>一切皆有可能</title><!--这里是山世销标题-->

<hta:application sysmenu=no scroll=no border=none>

<script language="vc">

sub sub1

me.close

end sub

me.resizeto 500,410 '这里设置窗口大小,单位为像素

me.moveto 260,100 '这里设置窗口位置,单位为像素

window.settimeout "sub1",100000 '这是设置时间,单位为毫秒,我这里设置为12秒

</script>

<body>

<CENTER>

<FONT style="COLOR:#33FF00FILTER: shadow(color=black)FONT-FAMILY: 华文彩云FONT-SIZE: 30ptLINE-HEIGHT: 150%WIDTH: 100%"返旅><B>一切皆有可能</B></FONT></CENTER>

<hr>

<style type="text/css">

.3dfont { FILTER: glow(color=ffffff,strength=0) shadow(color=cccccc,direction:135)POSITION: relativeWIDTH: 100% }

</style>

<table border="0" width="100%">

<tr>

<td width="100%" class="3dfont"><font color=RED><逗游CENTER>☆☆☆☆☆☆ 献给最亲爱的你 ☆☆☆☆☆☆</font>

<br>

<P align=left>

★一切皆有可能!</B><br><br>

一切皆有可能!</B><br><br>

<MARQUEE>希望大家多多支持!!!</body>

</html>


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/8282647.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-15
下一篇 2023-04-15

发表评论

登录后才能评论

评论列表(0条)

保存