1. 程式人生 > >java 練習7 打印當前時間

java 練習7 打印當前時間

normal java 練習 代碼 cond second 學習 ava min style

打印當前時間。學習使用Date類和Calendar類。(教材P194頁)

代碼

package javawork;
import java.util.Calendar;
public class Time {
public static void main(String[] args) {
Calendar calender=Calendar.getInstance();
int year=calender.get(Calendar.YEAR);
int month=calender.get(Calendar.MONTH);
int date=calender.get(Calendar.DATE);
int hour=calender.get(Calendar.HOUR_OF_DAY); int minute=calender.get(Calendar.MINUTE); int second=calender.get(Calendar.SECOND); int week=calender.get(Calendar.DAY_OF_WEEK); System.out.println(year + "/" + month + "/" + date + " " +hour + ":" +minute + ":" + second + "星期:"+(week-1)); } }

運行結果

技術分享

java 練習7 打印當前時間