公共类ShowCurrentTime
{
public static void main(String [] args)
{
// Obtain the total milliseconds
long totalMilliseconds = System.currentTimeMillis();
// Obtain the total seconds
long totalSeconds = totalMilliseconds / 1000;
// Compute the current second in the minute in the hour
long currentSecond = totalSeconds % 60;
// Obtain the total minutes
long totalMinutes = totalSeconds / 60;
// Compute the current minute in the hour
long currentMinute = (totalMinutes % 60);
// Obtain the total hours
long totalHours = totalMinutes / 60;
// Compute the current hour
long currentHour = totalHours % 24;
// Display results
System.out.println("Current time is " + currentHour + ":" + currentMinute + ":" + currentSecond + "GMT");
}
}
运行这些代码,给出GMT,如何配置它以获取某个时区的当前时间,如GMT +5:30(IST)?
答案 0 :(得分:0)
次是UTC,如果你需要在不同的时区显示它,你可以使用Calendar类并设置你想要的时区