import javax.swing.JOptionPane;public class DisplayCurrentTime
{
public static void main(String[] args)
{
long totalmillsecond = System.currentTimeMillis();
long totalsecond = totalmillsecond / 1000;
long totalminute = totalsecond / 60;
long totalhour = totalminute / 60;
int currenthour = (int)(totalhour % 24);
int currentminute = (int)(totalminute % 60);
int currentsecond = (int)(totalsecond % 60);
String output = "Current Time:" + currenthour + ":" + currentminute + ":" + currentsecond ;
JOptionPane.showMessageDialog(null,output);
}
}这个程序运行结果中的分钟和秒数正确,但是小时数不正确。请指点。我用的是windows 2003 server。
{
public static void main(String[] args)
{
long totalmillsecond = System.currentTimeMillis();
long totalsecond = totalmillsecond / 1000;
long totalminute = totalsecond / 60;
long totalhour = totalminute / 60;
int currenthour = (int)(totalhour % 24);
int currentminute = (int)(totalminute % 60);
int currentsecond = (int)(totalsecond % 60);
String output = "Current Time:" + currenthour + ":" + currentminute + ":" + currentsecond ;
JOptionPane.showMessageDialog(null,output);
}
}这个程序运行结果中的分钟和秒数正确,但是小时数不正确。请指点。我用的是windows 2003 server。
看看下面这个例子:
String time = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss")
.format(new Date());
JOptionPane.showMessageDialog(null, time);
Calendar today= new GregorianCalendar();
long time=today.getTimeInMillis();//返回此 Calendar 的时间值,以毫秒为单位。
int t_Year=today.get(Calendar.YEAR);
int t_Month=today.get(Calendar.MONTH);
int t_Day=today.get(Calendar.DAY_OF_MONTH);
int t_Hour=today.get(Calendar.HOUR_OF_DAY);
int t_MinuTe=today.get(Calendar.MINUTE);
int t_Second=today.get(Calendar.SECOND);
这个不存在时区问题