package huu;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Scanner;
public class Test {
/**
* 计算对应年份的生肖
* @param year 给定年份
* @return 返回生肖的字符串
*/
private static String getZodica(int year) {
final String[] Animals = new String[] { "鼠", "牛", "虎", "兔", "龙", "蛇",
"马", "羊", "猴", "鸡", "狗", "猪" };
return Animals[(year - 4) % 12];
}
/**
* 计算对应年份的干支
* @param year 给定年份
* @return 返回干支字符串
*/
private static String Gan_Zhi(int year) {
final String[] Gan = new String[] { "甲", "乙", "丙", "丁", "戊", "己", "庚",
"辛", "壬", "癸" };
final String[] Zhi = new String[] { "子", "丑", "寅", "卯", "辰", "巳", "午",
"未", "申", "酉", "戌", "亥" };
return (Gan[(year-4) % 10] + Zhi[(year-4) % 12]);
}
public static void Time(){
System.out.println("请输入年份:");
}
public static void main(String[] args) {
SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar now = java.util.Calendar.getInstance();
System.out.println(dateformat.format(now.getTime()));//获取当前系统时间
java.util.Calendar startData=java.util.Calendar.getInstance();
java.util.Calendar endData=java.util.Calendar.getInstance();
startData.set(2015,9,25);
endData.set(2017,8,13);//分别输出两个时间的值
Long dateLen = Math.abs((endData.getTimeInMillis()-startData.getTimeInMillis())/(24*60*60*1000));//获取相减值的绝对值
System.out.println(dateLen);//输出时间差
Scanner scanner = new Scanner(System.in);
System.out.print("请输入年份:");
int year = scanner.nextInt();
System.out.println("生肖:"+getZodica(year)+"\n干支:"+Gan_Zhi(year));
}
}
慕的地8582982
To_The_Moon
相关分类