close
標題:

JAVA關於時間問題??

發問:

Time abc= new Time(23,59); 代表23點59分 可否能把abc變為只有分鐘,沒有小時?? 是什麼COMMAND??

最佳解答:

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)); } }

免費註冊體驗

 

此文章來自奇摩知識+如有不便請留言告知

其他解答:
arrow
arrow

    yanahv7 發表在 痞客邦 留言(0) 人氣()