时间戳Plus版

    static int[] monthDay = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

public static void main(String[] args) {
int[] arr = new int[9];
long timeStamp = System.currentTimeMillis();
arr[8] = (int) day(timeStamp);
arr[0] = yearOf0Year(arr);
arr[1] = monthOfYear(arr);
arr[2] = hourOfDay(arr, timeStamp);
arr[3] = minuteOfHour(arr, timeStamp);
arr[4] = secondOfMinute(arr, timeStamp);
// arr[1 = ]
System.out.println("从标准时间过时间");//day
System.out.println("经过秒" + arr[4]);//second
System.out.println("经过分钟" + arr[3]);//minute
System.out.println("经过小时" + arr[2]);//hour
System.out.println("经过天数" + arr[8]);//day
System.out.println("经过月数" + arr[1]);//month
System.out.println("经过年数" + arr[0]);//year
System.out.println();
System.out.println("当前时间 东八区" + (arr[0] + 1) + "-" + (arr[1] + 1) + "-" + (arr[8] - 1) + " " + (arr[2] + 8) + ":" + arr[3] + ":" + arr[4]);
}

static double day(long timeStamp) {
double day = Math.ceil(timeStamp / (24 * 60 * 60 * 1000));
return day;
}

static int lipyear(int year) {
if ((year % 4 == 0 && year % 10 != 0) || year % 400 == 0) {
return 1;
}
return 0;
}

static int yearOf0Year(int[] arr) {
int year = 0;
for (int i = 1970; arr[8] > 365 + lipyear(i); i++) {
arr[8] -= (365 + lipyear(i));
year = i;
}
return year;
}

static int monthOfYear(int[] arr) {
int month = 0;
for (int i = 1; arr[8] > monthDay[i]; i++) {
arr[8] -= (monthDay[i] + lipyear(arr[0] + 1));
month = i;
}
return month;
}

static int hourOfDay(int[] arr, long timeStamp) {
int hour = (int) Math.ceil(timeStamp % (24 * 60 * 60 * 1000));
hour /= 60 * 60 * 1000;
return hour;
}

static int minuteOfHour(int[] arr, long timeStamp) {
int minute = (int) Math.ceil(timeStamp % (60 * 60 * 1000));
minute /= 60 * 1000;
return minute;
}

static int secondOfMinute(int[] arr, long timeStamp) {
int second = (int) Math.ceil(timeStamp % (60 * 1000));
second /= 1000;
return second;
}
}
上一篇:Java 流程控制:if双选择结构


下一篇:证券从业考试如何备考?