package tw.xxx.myfirstproject.oop;

 

import javax.swing.JFrame;

 

public class CallTestPackageNImportEx1 {

 

   public static void main(String[] args) {

//    java.awt.List list1 =new java.awt.List();

//    因為list有兩個不同分類相同名字,所以需打全名(包含awt這個目錄名稱),才能找到自己要的

//如果要impotr自己同packge的類別,需要輸入整個路徑,例如:

//import tw.xxx.myfirstproject.oop.mypackage.TestPackageNImportEx1;

      JFrame jf = new JFrame("test");

      jf.setSize(300,500);

      jf.setVisible(true);

   }

}


產生一個視窗



package tw.xxx.myfirstproject.oop;

 

import java.util.Calendar;

import java.util.Date;

 

public class TestCalenderEx1 {

 

 

   public static void main(String[] args) {

      Date date = new Date();

      System.out.println("date:"+date);

      //星期///時間/

      //因為Date中有改寫toString

     

      Calendar calender = Calendar.getInstance();//產生一個Calendar.getInstance()物件

      //public abstract class Calendar

      //Calendar是抽象類別,所以無法被new,只能直接用他的方法

      //Calendar provides a class method, getInstance,

      //for getting a generally useful object of this type.

      //Calendar's getInstance method returns a Calendar object whose calendar fields

      //have been initialized with the current date and time:

      int mydate = calender.get(Calendar.DATE);

      System.out.println("mydate="+mydate);

      //本月中的第幾日

     

      int myHour = calender.get(Calendar.HOUR_OF_DAY);

      System.out.println("myHour="+myHour);

      //24制,幾點

     

      int year = calender.get(Calendar.YEAR);

      System.out.println("year="+year);

      //西元年

     

   }

 

}



date:Sun Mar 20 17:16:31 CST 2016
mydate=20
myHour=17
year=2016




2016/03/25新增

package com.xxx.xxx.tina.selfjdbcpractice;

import java.util.Calendar;

import java.util.Date;

 

public class todaysDate {

 

    public static void main(String[] args) {

       int todaysYear = Calendar.getInstance().get(Calendar.YEAR);

       int todaysMonth = Calendar.getInstance().get(Calendar.MONTH)+1;//月份從0開始

       int todaysDate = Calendar.getInstance().get(Calendar.DATE);

        System.out.println("date:"+todaysYear+"/"+todaysMonth+"/"+todaysDate );

    }

}


date:2016/3/25
 




package com.xxx.selfjdbcpractice;

import java.text.SimpleDateFormat;

import java.util.Date;

 

public class todaysDate {

 

    public static void main(String[] args) {

       Date today = new Date();

       SimpleDateFormat sdf = new SimpleDateFormat("yyy-MM-dd");

        System.out.println("date:"+sdf.format(today) );

    }

}


date:2016-03-25




package com.xxx.xxx.selfjdbcpractice;

import java.util.Date;

 

public class todaysDate {

 

    public static void main(String[] args) {

       Date today = new Date(System.currentTimeMillis());

        System.out.println("date:"+today );

    }

}


date:Fri Mar 25 12:11:50 CST 2016

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 乙方 的頭像
    乙方

    學習筆記專區

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