Date today = new Date(); System.out.println(today);//这个就是今天的时间了 System.out.println(today.getYear());//这个就是今天的年了 System.out.println(today.getDate());//这个就是今天的日期了 ..........
import java.text.SimpleDateFormat; import java.util.Date; public class DateTest{ public static void main(String[] args){ Date myDate=new Date(System.currentTimeMillis()); //This time format is your local time format. System.out.println(myDate.toString()); //Used the simple format to get the String you want . //The valid string ,you can reference the JDK Doc SimpleDateFormat sDateFormat=new SimpleDateFormat("yyyy/MM/DD HH:mm:ss"); System.out.println(sDateFormat.format(myDate)); } }
Date date = new Date(); Timestamp time = new Timestamp(date.getTime()); System.out.println(time.toString());
public class GregorianCalendar extends Calendar GregorianCalendar is a concrete subclass of Calendar and provides the standard calendar used by most of the world.
System.out.println(today);//这个就是今天的时间了
System.out.println(today.getYear());//这个就是今天的年了
System.out.println(today.getDate());//这个就是今天的日期了
..........
import java.util.Date;
public class DateTest{
public static void main(String[] args){
Date myDate=new Date(System.currentTimeMillis());
//This time format is your local time format.
System.out.println(myDate.toString());
//Used the simple format to get the String you want .
//The valid string ,you can reference the JDK Doc
SimpleDateFormat sDateFormat=new SimpleDateFormat("yyyy/MM/DD HH:mm:ss");
System.out.println(sDateFormat.format(myDate));
}
}
Timestamp time = new Timestamp(date.getTime());
System.out.println(time.toString());
{....
GregorianCalendar d=new Gregorian();
d.get(Calendar.DAY_OF_WEEK);
d.get(Calendar.HOUR);}Data 类已经不被1.42推荐
查阅API便知
extends Calendar
GregorianCalendar is a concrete subclass of Calendar and provides the standard calendar used by most of the world.