import javax.swing.JOptionPane;
publicclassTEST {publicstaticvoidmain(String[] args) {
long totalMilliseconds = System.currentTimeMillis();
long totalSeconds = (totalMilliseconds / 1000);
int currentSecond = (int)(totalSeconds % 60);
long totalMinutes = totalSeconds / 60;
int currentMinute = (int)(totalMinutes % 60);
long totalHours = totalMinutes / 60 + 8; //简单粗暴int currentHour = (int)(totalHours % 24);
int totalDays = (int)(totalHours / 24);
if (currentHour > 0) totalDays++;
int currentYear = 2000;
do {
currentYear++;
} while (getTotalDaysInYears(currentYear) < totalDays);
int totalNumOfDaysInTheYear = totalDays -getTotalDaysInYears(currentYear - 1);
int currentMonth = 0;
do {
currentMonth++;
} while (getTotalDaysInMonths(currentYear, currentMonth)
< totalNumOfDaysInTheYear);
int currentDay = totalNumOfDaysInTheYear -
getTotalDaysInMonths(currentYear, currentMonth - 1);
String output = "Current date and time is " +
currentMonth + "/" + currentDay + "/" + currentYear + " " +
currentHour + ":" +
+ currentMinute + ":" + currentSecond + " GMT";
JOptionPane.showMessageDialog(null, output);
}
/** Get the total number of days from Jan 1, 1970 to the specified year*/staticint getTotalDaysInYears(int year) {
int total = 0;
// Get the total days from 1970 to the specified yearfor (int i = 1970; i <= year; i++)
if (isLeapYear(i))
total = total + 366;
else
total = total + 365;
return total;
}
/** Get the total number of days from Jan 1 to the month in the year*/staticint getTotalDaysInMonths(int year, int month) {
int total = 0;
// Add days from Jan to the monthfor (int i = 1; i <= month; i++)
total = total + getNumOfDaysInMonth(year, i);
return total;
}
/** Get the number of days in a month */staticint getNumOfDaysInMonth(int year, int month) {
if (month == 1 || month==3 || month == 5 || month == 7 ||
month == 8 || month == 10 || month == 12)
return31;
if (month == 4 || month == 6 || month == 9 || month == 11)
return30;
if (month == 2)
if (isLeapYear(year))
return29;
elsereturn28;
return0; // If month is incorrect.
}
/** Determine if it is a leap year */staticboolean isLeapYear(int year) {
if ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)))
returntrue;
returnfalse;
}
}
import javax.swing.JOptionPane;public class TEST { public static void main(String[] args) { long totalMilliseconds = System.currentTimeMillis(); long totalSeconds = (totalMilliseconds / 1000