JAVA關於時間問題??

2008-12-27 1:22 am
Time abc= new Time(23,59);

代表23點59分


可否能把abc變為只有分鐘,沒有小時??

是什麼COMMAND??

回答 (1)

2008-12-27 1:18 pm
✔ 最佳答案
The Time class has many deprecated methods, which do not include one to extract minutes.
The Calendar abstract class is generally used for time calcualtions. Here are some examples of its use. If you want to have just the minutes and not hours, you can create your own class for that purpose. The examples below include one which extracts the current minute as an int.
If you need more info, PM or post supplementary questions.
import java.util.Calendar;
import java.sql.Time;
public class TestTime
{
public static void setTime(Calendar cal, int hour, int min)
{
cal.set(cal.HOUR_OF_DAY,hour);
cal.set(cal.MINUTE,min);
}
public static int getMinute(Calendar cal)
{
return cal.get(Calendar.MINUTE);
}
public static void main(String[] args)
{
Calendar now=Calendar.getInstance();
System.out.printf("Minutes=%d\n",now.get(Calendar.MINUTE));
// Time abc=new Time(23,59,0);
Calendar abc=Calendar.getInstance();
setTime(abc,23,59);
System.out.printf("Minutes=%d\n",abc.get(Calendar.MINUTE));
System.out.printf("Minutes=%d\n",getMinute(abc));
}
}



收錄日期: 2021-04-13 16:19:17
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20081226000051KK01220

檢視 Wayback Machine 備份